Skip to content

Commit 4176605

Browse files
floatiouskwilczynski
authored andcommitted
PCI: endpoint: pci-epf-test: Simplify pci_epf_test_alloc_space() loop
Make pci-epf-test use pci_epc_get_next_free_bar() just like pci-epf-ntb.c and pci-epf-vntb.c. Using pci_epc_get_next_free_bar() also makes it more obvious that pci-epf-test does no special configuration at all. (The only configuration pci-epf-test does is setting PCI_BASE_ADDRESS_MEM_TYPE_64 if epc_features has marked the specific BAR as only_64bit. pci_epc_get_next_free_bar() already takes only_64bit into account when looping.) This way, the code is more consistent between EPF drivers, and pci-epf-test does not need to explicitly check if the BAR is reserved, or if the index belongs to a BAR succeeding a 64-bit only BAR. Link: https://lore.kernel.org/linux-pci/[email protected] Signed-off-by: Niklas Cassel <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]>
1 parent 4cece76 commit 4176605

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

drivers/pci/endpoint/functions/pci-epf-test.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -817,14 +817,13 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
817817
{
818818
struct pci_epf_test *epf_test = epf_get_drvdata(epf);
819819
struct device *dev = &epf->dev;
820-
struct pci_epf_bar *epf_bar;
821820
size_t msix_table_size = 0;
822821
size_t test_reg_bar_size;
823822
size_t pba_size = 0;
824823
bool msix_capable;
825824
void *base;
826-
int bar, add;
827825
enum pci_barno test_reg_bar = epf_test->test_reg_bar;
826+
enum pci_barno bar;
828827
const struct pci_epc_features *epc_features;
829828
size_t test_reg_size;
830829

@@ -849,16 +848,14 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
849848
}
850849
epf_test->reg[test_reg_bar] = base;
851850

852-
for (bar = 0; bar < PCI_STD_NUM_BARS; bar += add) {
853-
epf_bar = &epf->bar[bar];
854-
add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1;
851+
for (bar = BAR_0; bar < PCI_STD_NUM_BARS; bar++) {
852+
bar = pci_epc_get_next_free_bar(epc_features, bar);
853+
if (bar == NO_BAR)
854+
break;
855855

856856
if (bar == test_reg_bar)
857857
continue;
858858

859-
if (epc_features->bar[bar].type == BAR_RESERVED)
860-
continue;
861-
862859
base = pci_epf_alloc_space(epf, bar_size[bar], bar,
863860
epc_features, PRIMARY_INTERFACE);
864861
if (!base)

0 commit comments

Comments
 (0)