@@ -128,6 +128,18 @@ enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features
128
128
}
129
129
EXPORT_SYMBOL_GPL (pci_epc_get_next_free_bar );
130
130
131
+ static bool pci_epc_function_is_valid (struct pci_epc * epc ,
132
+ u8 func_no , u8 vfunc_no )
133
+ {
134
+ if (IS_ERR_OR_NULL (epc ) || func_no >= epc -> max_functions )
135
+ return false;
136
+
137
+ if (vfunc_no > 0 && (!epc -> max_vfs || vfunc_no > epc -> max_vfs [func_no ]))
138
+ return false;
139
+
140
+ return true;
141
+ }
142
+
131
143
/**
132
144
* pci_epc_get_features() - get the features supported by EPC
133
145
* @epc: the features supported by *this* EPC device will be returned
@@ -145,10 +157,7 @@ const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
145
157
{
146
158
const struct pci_epc_features * epc_features ;
147
159
148
- if (IS_ERR_OR_NULL (epc ) || func_no >= epc -> max_functions )
149
- return NULL ;
150
-
151
- if (vfunc_no > 0 && (!epc -> max_vfs || vfunc_no > epc -> max_vfs [func_no ]))
160
+ if (!pci_epc_function_is_valid (epc , func_no , vfunc_no ))
152
161
return NULL ;
153
162
154
163
if (!epc -> ops -> get_features )
@@ -218,10 +227,7 @@ int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
218
227
{
219
228
int ret ;
220
229
221
- if (IS_ERR_OR_NULL (epc ) || func_no >= epc -> max_functions )
222
- return - EINVAL ;
223
-
224
- if (vfunc_no > 0 && (!epc -> max_vfs || vfunc_no > epc -> max_vfs [func_no ]))
230
+ if (!pci_epc_function_is_valid (epc , func_no , vfunc_no ))
225
231
return - EINVAL ;
226
232
227
233
if (!epc -> ops -> raise_irq )
@@ -262,10 +268,7 @@ int pci_epc_map_msi_irq(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
262
268
{
263
269
int ret ;
264
270
265
- if (IS_ERR_OR_NULL (epc ))
266
- return - EINVAL ;
267
-
268
- if (vfunc_no > 0 && (!epc -> max_vfs || vfunc_no > epc -> max_vfs [func_no ]))
271
+ if (!pci_epc_function_is_valid (epc , func_no , vfunc_no ))
269
272
return - EINVAL ;
270
273
271
274
if (!epc -> ops -> map_msi_irq )
@@ -293,10 +296,7 @@ int pci_epc_get_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no)
293
296
{
294
297
int interrupt ;
295
298
296
- if (IS_ERR_OR_NULL (epc ) || func_no >= epc -> max_functions )
297
- return 0 ;
298
-
299
- if (vfunc_no > 0 && (!epc -> max_vfs || vfunc_no > epc -> max_vfs [func_no ]))
299
+ if (!pci_epc_function_is_valid (epc , func_no , vfunc_no ))
300
300
return 0 ;
301
301
302
302
if (!epc -> ops -> get_msi )
@@ -329,11 +329,10 @@ int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u8 interrupts)
329
329
int ret ;
330
330
u8 encode_int ;
331
331
332
- if (IS_ERR_OR_NULL (epc ) || func_no >= epc -> max_functions ||
333
- interrupts < 1 || interrupts > 32 )
332
+ if (!pci_epc_function_is_valid (epc , func_no , vfunc_no ))
334
333
return - EINVAL ;
335
334
336
- if (vfunc_no > 0 && (! epc -> max_vfs || vfunc_no > epc -> max_vfs [ func_no ]) )
335
+ if (interrupts < 1 || interrupts > 32 )
337
336
return - EINVAL ;
338
337
339
338
if (!epc -> ops -> set_msi )
@@ -361,10 +360,7 @@ int pci_epc_get_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no)
361
360
{
362
361
int interrupt ;
363
362
364
- if (IS_ERR_OR_NULL (epc ) || func_no >= epc -> max_functions )
365
- return 0 ;
366
-
367
- if (vfunc_no > 0 && (!epc -> max_vfs || vfunc_no > epc -> max_vfs [func_no ]))
363
+ if (!pci_epc_function_is_valid (epc , func_no , vfunc_no ))
368
364
return 0 ;
369
365
370
366
if (!epc -> ops -> get_msix )
@@ -397,11 +393,10 @@ int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
397
393
{
398
394
int ret ;
399
395
400
- if (IS_ERR_OR_NULL (epc ) || func_no >= epc -> max_functions ||
401
- interrupts < 1 || interrupts > 2048 )
396
+ if (!pci_epc_function_is_valid (epc , func_no , vfunc_no ))
402
397
return - EINVAL ;
403
398
404
- if (vfunc_no > 0 && (! epc -> max_vfs || vfunc_no > epc -> max_vfs [ func_no ]) )
399
+ if (interrupts < 1 || interrupts > 2048 )
405
400
return - EINVAL ;
406
401
407
402
if (!epc -> ops -> set_msix )
@@ -428,10 +423,7 @@ EXPORT_SYMBOL_GPL(pci_epc_set_msix);
428
423
void pci_epc_unmap_addr (struct pci_epc * epc , u8 func_no , u8 vfunc_no ,
429
424
phys_addr_t phys_addr )
430
425
{
431
- if (IS_ERR_OR_NULL (epc ) || func_no >= epc -> max_functions )
432
- return ;
433
-
434
- if (vfunc_no > 0 && (!epc -> max_vfs || vfunc_no > epc -> max_vfs [func_no ]))
426
+ if (!pci_epc_function_is_valid (epc , func_no , vfunc_no ))
435
427
return ;
436
428
437
429
if (!epc -> ops -> unmap_addr )
@@ -459,10 +451,7 @@ int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
459
451
{
460
452
int ret ;
461
453
462
- if (IS_ERR_OR_NULL (epc ) || func_no >= epc -> max_functions )
463
- return - EINVAL ;
464
-
465
- if (vfunc_no > 0 && (!epc -> max_vfs || vfunc_no > epc -> max_vfs [func_no ]))
454
+ if (!pci_epc_function_is_valid (epc , func_no , vfunc_no ))
466
455
return - EINVAL ;
467
456
468
457
if (!epc -> ops -> map_addr )
@@ -489,12 +478,11 @@ EXPORT_SYMBOL_GPL(pci_epc_map_addr);
489
478
void pci_epc_clear_bar (struct pci_epc * epc , u8 func_no , u8 vfunc_no ,
490
479
struct pci_epf_bar * epf_bar )
491
480
{
492
- if (IS_ERR_OR_NULL (epc ) || func_no >= epc -> max_functions ||
493
- (epf_bar -> barno == BAR_5 &&
494
- epf_bar -> flags & PCI_BASE_ADDRESS_MEM_TYPE_64 ))
481
+ if (!pci_epc_function_is_valid (epc , func_no , vfunc_no ))
495
482
return ;
496
483
497
- if (vfunc_no > 0 && (!epc -> max_vfs || vfunc_no > epc -> max_vfs [func_no ]))
484
+ if (epf_bar -> barno == BAR_5 &&
485
+ epf_bar -> flags & PCI_BASE_ADDRESS_MEM_TYPE_64 )
498
486
return ;
499
487
500
488
if (!epc -> ops -> clear_bar )
@@ -521,18 +509,16 @@ int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
521
509
int ret ;
522
510
int flags = epf_bar -> flags ;
523
511
524
- if (IS_ERR_OR_NULL (epc ) || func_no >= epc -> max_functions ||
525
- (epf_bar -> barno == BAR_5 &&
526
- flags & PCI_BASE_ADDRESS_MEM_TYPE_64 ) ||
512
+ if (!pci_epc_function_is_valid (epc , func_no , vfunc_no ))
513
+ return - EINVAL ;
514
+
515
+ if ((epf_bar -> barno == BAR_5 && flags & PCI_BASE_ADDRESS_MEM_TYPE_64 ) ||
527
516
(flags & PCI_BASE_ADDRESS_SPACE_IO &&
528
517
flags & PCI_BASE_ADDRESS_IO_MASK ) ||
529
518
(upper_32_bits (epf_bar -> size ) &&
530
519
!(flags & PCI_BASE_ADDRESS_MEM_TYPE_64 )))
531
520
return - EINVAL ;
532
521
533
- if (vfunc_no > 0 && (!epc -> max_vfs || vfunc_no > epc -> max_vfs [func_no ]))
534
- return - EINVAL ;
535
-
536
522
if (!epc -> ops -> set_bar )
537
523
return 0 ;
538
524
@@ -561,10 +547,7 @@ int pci_epc_write_header(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
561
547
{
562
548
int ret ;
563
549
564
- if (IS_ERR_OR_NULL (epc ) || func_no >= epc -> max_functions )
565
- return - EINVAL ;
566
-
567
- if (vfunc_no > 0 && (!epc -> max_vfs || vfunc_no > epc -> max_vfs [func_no ]))
550
+ if (!pci_epc_function_is_valid (epc , func_no , vfunc_no ))
568
551
return - EINVAL ;
569
552
570
553
/* Only Virtual Function #1 has deviceID */
0 commit comments