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 |
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);
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(-)