Skip to content

Commit 4147c2f

Browse files
westeribjorn-helgaas
authored andcommitted
PCI: Open-code the two pass loop when scanning bridges
The current scanning code is really hard to understand because it calls the same function in a loop where pass value is changed without any comments explaining it: for (pass = 0; pass < 2; pass++) for_each_pci_bridge(dev, bus) max = pci_scan_bridge(bus, dev, max, pass); Unfamiliar reader cannot tell easily what is the purpose of this loop without looking at internals of pci_scan_bridge(). In order to make this bit easier to understand, open-code the loop in pci_scan_child_bus() and pci_hp_add_bridge() with added comments. No functional changes intended. Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 95e3ba9 commit 4147c2f

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

drivers/pci/probe.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,7 +2398,7 @@ void __weak pcibios_fixup_bus(struct pci_bus *bus)
23982398

23992399
unsigned int pci_scan_child_bus(struct pci_bus *bus)
24002400
{
2401-
unsigned int devfn, pass, max = bus->busn_res.start;
2401+
unsigned int devfn, max = bus->busn_res.start;
24022402
struct pci_dev *dev;
24032403

24042404
dev_dbg(&bus->dev, "scanning bus\n");
@@ -2420,9 +2420,17 @@ unsigned int pci_scan_child_bus(struct pci_bus *bus)
24202420
bus->is_added = 1;
24212421
}
24222422

2423-
for (pass = 0; pass < 2; pass++)
2424-
for_each_pci_bridge(dev, bus)
2425-
max = pci_scan_bridge(bus, dev, max, pass);
2423+
/*
2424+
* Scan bridges that are already configured. We don't touch them
2425+
* unless they are misconfigured (which will be done in the second
2426+
* scan below).
2427+
*/
2428+
for_each_pci_bridge(dev, bus)
2429+
max = pci_scan_bridge(bus, dev, max, 0);
2430+
2431+
/* Scan bridges that need to be reconfigured */
2432+
for_each_pci_bridge(dev, bus)
2433+
max = pci_scan_bridge(bus, dev, max, 1);
24262434

24272435
/*
24282436
* Make sure a hotplug bridge has at least the minimum requested
@@ -2739,7 +2747,7 @@ void __init pci_sort_breadthfirst(void)
27392747
int pci_hp_add_bridge(struct pci_dev *dev)
27402748
{
27412749
struct pci_bus *parent = dev->bus;
2742-
int pass, busnr, start = parent->busn_res.start;
2750+
int busnr, start = parent->busn_res.start;
27432751
int end = parent->busn_res.end;
27442752

27452753
for (busnr = start; busnr <= end; busnr++) {
@@ -2750,8 +2758,13 @@ int pci_hp_add_bridge(struct pci_dev *dev)
27502758
dev_err(&dev->dev, "No bus number available for hot-added bridge\n");
27512759
return -1;
27522760
}
2753-
for (pass = 0; pass < 2; pass++)
2754-
busnr = pci_scan_bridge(parent, dev, busnr, pass);
2761+
2762+
/* Scan bridges that are already configured */
2763+
busnr = pci_scan_bridge(parent, dev, busnr, 0);
2764+
2765+
/* Scan bridges that need to be reconfigured */
2766+
pci_scan_bridge(parent, dev, busnr, 1);
2767+
27552768
if (!dev->subordinate)
27562769
return -1;
27572770

0 commit comments

Comments
 (0)