Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH -next 1/3] PCI: fix double put_device() in error case in pci_create_root_bus()
@ 2022-08-25 12:27 Yang Yingliang
  2022-08-25 12:27 ` [PATCH -next 2/3] PCI: fix possible memory leak in error case in pci_register_host_bridge() Yang Yingliang
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Yang Yingliang @ 2022-08-25 12:27 UTC (permalink / raw)
  To: linux-kernel, linux-pci; +Cc: bhelgaas

If device_add() fails in pci_register_host_bridge(), the brigde device will
be put once, and it will be put again in error path of pci_create_root_bus().
Move the put_device() from pci_create_root_bus() to pci_register_host_bridge()
to fix this problem. And use device_unregister() instead of del_device() and
put_device().

Fixes: 9885440b16b8 ("PCI: Fix pci_host_bridge struct device release/free handling")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/pci/probe.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index c5286b027f00..e500eb9d6468 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1027,7 +1027,7 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge)
 
 unregister:
 	put_device(&bridge->dev);
-	device_del(&bridge->dev);
+	device_unregister(&bridge->dev);
 
 free:
 	kfree(bus);
@@ -3037,13 +3037,9 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
 
 	error = pci_register_host_bridge(bridge);
 	if (error < 0)
-		goto err_out;
+		return NULL;
 
 	return bridge->bus;
-
-err_out:
-	put_device(&bridge->dev);
-	return NULL;
 }
 EXPORT_SYMBOL_GPL(pci_create_root_bus);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-08-27  9:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-25 12:27 [PATCH -next 1/3] PCI: fix double put_device() in error case in pci_create_root_bus() Yang Yingliang
2022-08-25 12:27 ` [PATCH -next 2/3] PCI: fix possible memory leak in error case in pci_register_host_bridge() Yang Yingliang
2022-08-26 22:38   ` Bjorn Helgaas
2022-08-27  9:29     ` Yang Yingliang
2022-08-25 12:27 ` [PATCH -next 3/3] PCI: fix handle error case in pci_alloc_child_bus() Yang Yingliang
2022-08-26 21:14 ` [PATCH -next 1/3] PCI: fix double put_device() in error case in pci_create_root_bus() Bjorn Helgaas
2022-08-27  9:15   ` Yang Yingliang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox