Skip to contentSkip to conversation

PCI: fix double put_device() in error case in pci_create_root_bus()

PATCH In review Yang Yingliang 2 participants 3 messages Oct 18, 2022 – Nov 23, 2022 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: fix double put_device() in error case in pci_create_root_bus()

If device_add() fails in pci_register_host_bridge(), the bridge device will be put once, and it will be put again in error path of pci_create_root_bus(). Fix this by removing put_device() after device_add() is failed.

Fixes 37d6a0a6f470 ("PCI: Add pci_register_host_bridge() interface")
---
 drivers/pci/probe.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/pci/probe.c +1 -3
index b66fa42c4b1f..f61754d76aa7 100644
@@ -926,10 +926,8 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge)
 	/* Temporarily move resources off the list */
 	list_splice_init(&bridge->windows, &resources);
 	err = device_add(&bridge->dev);
-	if (err) {
-		put_device(&bridge->dev);
+	if (err)
 		goto free;
-	}
 	bus->bridge = get_device(&bridge->dev);
 	device_enable_async_suspend(bus->bridge);
 	pci_set_bus_of_node(bus);
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Yang Yingliang

If device_add() fails in pci_register_host_bridge(), the bridge device will be put once, and it will be put again in error path of pci_create_root_bus(). Fix this by removing put_device() after device_add() is failed.

Fixes 37d6a0a6f470 ("PCI: Add pci_register_host_bridge() interface")
---
 drivers/pci/probe.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Seems fine. All callers, as far as I can tell, of this end up invoking pci_free_host_bridge() which does the corresponding put_device() itself:

#2 lore raw

Hi Helgaas,

Quoted 4 lines · Thierry Reding
Quoted 3 lines · Yang Yingliang

If device_add() fails in pci_register_host_bridge(), the bridge device will be put once, and it will be put again in error path of pci_create_root_bus(). Fix this by removing put_device() after device_add() is failed.

I think it's a obvious problem.
Is this patch look good to you or any suggestion?

Thanks,
Yang

Quoted 10 lines
Quoted 6 lines
Fixes 37d6a0a6f470 ("PCI: Add pci_register_host_bridge() interface")
---
  drivers/pci/probe.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

Seems fine. All callers, as far as I can tell, of this end up invoking pci_free_host_bridge() which does the corresponding put_device() itself: