[PATCH] PCI: Clear the bridge's subordinate pointer when child bus registration fails

From: lirongqing

Date: Tue Nov 10 2026 - 00:36:59 EST


From: Li RongQing <lirongqing@xxxxxxxxx>

pci_alloc_child_bus() stores the new bus in bridge->subordinate before
device_register(&child->dev). If registration fails,
put_device(&child->dev) runs release_pcibus_dev() and frees the bus, but
bridge->subordinate still points at it.

The caller returns without scanning the new bus, yet the rest of the rescan
or removal path still follows dev->subordinate:
pci_assign_unassigned_bridge_resources() and pci_stop_bus_device() walk
bus->devices of the freed bus.

Clear the pointer before dropping the reference.

Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx>
---
drivers/pci/probe.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 86dbfd4..e07e189 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1269,6 +1269,8 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
pci_set_bus_msi_domain(child);
ret = device_register(&child->dev);
if (WARN_ON(ret < 0)) {
+ if (bridge)
+ bridge->subordinate = NULL;
put_device(&child->dev);
return NULL;
}
--
2.9.4