Messages in this thread Patch in this message | | | From | Yang Yingliang <> | Subject | [PATCH -next 3/3] PCI: fix handle error case in pci_alloc_child_bus() | Date | Thu, 25 Aug 2022 20:27:53 +0800 |
| |
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 --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); -- 2.25.1
| |