diff mbox series

[1/4] PCI: shpchp: bail out if pci_hp_add_bridge() fails

Message ID da60d5a41e8e554ca98d8d9b61e73291495bf820.1714762038.git.namcao@linutronix.de
State New
Headers show
Series check returned value of pci_hp_add_bridge() | expand

Commit Message

Nam Cao May 3, 2024, 7:23 p.m. UTC
If there is no bus number available for the downstream bus of the
hot-plugged bridge, pci_hp_add_bridge() will fail. The driver proceeds
regardless, and the kernel crashes.

Abort if pci_hp_add_bridge() fails.

Fixes: 7d01f70ac6f4 ("PCI: shpchp: use generic pci_hp_add_bridge()")
Signed-off-by: Nam Cao <namcao@linutronix.de>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: <stable@vger.kernel.org>
---
 drivers/pci/hotplug/shpchp_pci.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/pci/hotplug/shpchp_pci.c b/drivers/pci/hotplug/shpchp_pci.c
index 36db0c3c4ea6..2ac98bdc83d9 100644
--- a/drivers/pci/hotplug/shpchp_pci.c
+++ b/drivers/pci/hotplug/shpchp_pci.c
@@ -48,8 +48,13 @@  int shpchp_configure_device(struct slot *p_slot)
 	}
 
 	for_each_pci_bridge(dev, parent) {
-		if (PCI_SLOT(dev->devfn) == p_slot->device)
-			pci_hp_add_bridge(dev);
+		if (PCI_SLOT(dev->devfn) == p_slot->device) {
+			if (pci_hp_add_bridge(dev)) {
+				pci_stop_and_remove_bus_device(dev);
+				ret = -EINVAL;
+				goto out;
+			}
+		}
 	}
 
 	pci_assign_unassigned_bridge_resources(bridge);