[PATCH 1/8] PCI: Fix used_buses calculation in pci_scan_child_bus_extend()

Timo Aaltonen tjaalton at ubuntu.com
Fri Feb 10 08:50:45 UTC 2023


From: Mika Westerberg <mika.westerberg at linux.intel.com>

BugLink: https://bugs.launchpad.net/bugs/1991366

pci_scan_bridge_extend() returns the subordinate bus number needed to cover
all the buses below a bridge.  pci_scan_child_bus_extend() computes the
number of buses to reserve by comparing that with the current max bus
number.  Previously it did the subtraction in the wrong order, so
'used_buses' was nonsense.

Subtract 'max' from 'cmax' as is done for the similar
pci_scan_bridge_extend() call in the following block.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=216000
Fixes: 3374c545c27c ("PCI: Account for all bridges on bus when distributing bus numbers")
Link: https://lore.kernel.org/r/20220905080232.36087-2-mika.westerberg@linux.intel.com
Reported-by: Chris Chiu <chris.chiu at canonical.com>
Tested-by: Chris Chiu <chris.chiu at canonical.com>
Signed-off-by: Mika Westerberg <mika.westerberg at linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas at google.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko at linux.intel.com>
(cherry picked from commit 8066cc86b7aaaf6b4b38a81932459c6450440daa)
Signed-off-by: Timo Aaltonen <timo.aaltonen at canonical.com>
---
 drivers/pci/probe.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 4948531481d1..d7073b06dbc5 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2917,8 +2917,8 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus,
 		 * hotplug bridges too much during the second scan below.
 		 */
 		used_buses++;
-		if (cmax - max > 1)
-			used_buses += cmax - max - 1;
+		if (max - cmax > 1)
+			used_buses += max - cmax - 1;
 	}
 
 	/* Scan bridges that need to be reconfigured */
-- 
2.37.2




More information about the kernel-team mailing list