diff mbox series

[-next,3/3] PCI: fix handle error case in pci_alloc_child_bus()

Message ID 20220825122753.1838930-3-yangyingliang@huawei.com (mailing list archive)
State Superseded
Delegated to: Bjorn Helgaas
Headers show
Series [-next,1/3] PCI: fix double put_device() in error case in pci_create_root_bus() | expand

Commit Message

Yang Yingliang Aug. 25, 2022, 12:27 p.m. UTC
Return NULL pointer if device_register() fails, and call put_device()
to free the memory of pci bus and device name.

Fixes: 4f535093cf8f ("PCI: Put pci_dev in device tree as early as possible")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/pci/probe.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 292d9da146ce..c924f4e1ed38 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1144,7 +1144,10 @@  static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
 add_dev:
 	pci_set_bus_msi_domain(child);
 	ret = device_register(&child->dev);
-	WARN_ON(ret < 0);
+	if (WARN_ON(ret < 0)) {
+		put_device(&child->dev);
+		return NULL;
+	}
 
 	pcibios_add_bus(child);