diff options
author | Mika Westerberg <mika.westerberg@linux.intel.com> | 2017-10-13 14:35:42 -0400 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2017-11-06 19:48:58 -0500 |
commit | 4147c2fd9b12ae1e0bdbb2dbb9a9163c94a10a22 (patch) | |
tree | 89c4bef0de26de5ba5074623b819e2d596f2dd8f | |
parent | 95e3ba9772331502cc33f1e1d4a96f3310e2f31e (diff) |
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>
-rw-r--r-- | drivers/pci/probe.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 62d45a76f663..61813938d186 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c | |||
@@ -2398,7 +2398,7 @@ void __weak pcibios_fixup_bus(struct pci_bus *bus) | |||
2398 | 2398 | ||
2399 | unsigned int pci_scan_child_bus(struct pci_bus *bus) | 2399 | unsigned int pci_scan_child_bus(struct pci_bus *bus) |
2400 | { | 2400 | { |
2401 | unsigned int devfn, pass, max = bus->busn_res.start; | 2401 | unsigned int devfn, max = bus->busn_res.start; |
2402 | struct pci_dev *dev; | 2402 | struct pci_dev *dev; |
2403 | 2403 | ||
2404 | dev_dbg(&bus->dev, "scanning bus\n"); | 2404 | dev_dbg(&bus->dev, "scanning bus\n"); |
@@ -2420,9 +2420,17 @@ unsigned int pci_scan_child_bus(struct pci_bus *bus) | |||
2420 | bus->is_added = 1; | 2420 | bus->is_added = 1; |
2421 | } | 2421 | } |
2422 | 2422 | ||
2423 | for (pass = 0; pass < 2; pass++) | 2423 | /* |
2424 | for_each_pci_bridge(dev, bus) | 2424 | * Scan bridges that are already configured. We don't touch them |
2425 | max = pci_scan_bridge(bus, dev, max, pass); | 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); | ||
2426 | 2434 | ||
2427 | /* | 2435 | /* |
2428 | * Make sure a hotplug bridge has at least the minimum requested | 2436 | * Make sure a hotplug bridge has at least the minimum requested |
@@ -2739,7 +2747,7 @@ void __init pci_sort_breadthfirst(void) | |||
2739 | int pci_hp_add_bridge(struct pci_dev *dev) | 2747 | int pci_hp_add_bridge(struct pci_dev *dev) |
2740 | { | 2748 | { |
2741 | struct pci_bus *parent = dev->bus; | 2749 | struct pci_bus *parent = dev->bus; |
2742 | int pass, busnr, start = parent->busn_res.start; | 2750 | int busnr, start = parent->busn_res.start; |
2743 | int end = parent->busn_res.end; | 2751 | int end = parent->busn_res.end; |
2744 | 2752 | ||
2745 | for (busnr = start; busnr <= end; busnr++) { | 2753 | for (busnr = start; busnr <= end; busnr++) { |
@@ -2750,8 +2758,13 @@ int pci_hp_add_bridge(struct pci_dev *dev) | |||
2750 | dev_err(&dev->dev, "No bus number available for hot-added bridge\n"); | 2758 | dev_err(&dev->dev, "No bus number available for hot-added bridge\n"); |
2751 | return -1; | 2759 | return -1; |
2752 | } | 2760 | } |
2753 | for (pass = 0; pass < 2; pass++) | 2761 | |
2754 | busnr = pci_scan_bridge(parent, dev, busnr, pass); | 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 | |||
2755 | if (!dev->subordinate) | 2768 | if (!dev->subordinate) |
2756 | return -1; | 2769 | return -1; |
2757 | 2770 | ||