This reverts commit 804443c1f27883926de94c849d91f5b7d7d696e9. The newly added logic incorrectly sets bus_registered to true even when device_register returns an error, this is incorrect. When device_register fails, there is no need to release the reference count, and there are no direct error-handling operations following its execution. Therefore, this patch is meaningless and should be reverted. Fixes: 804443c1f278 ("PCI: Fix reference leak in pci_register_host_bridge()") Signed-off-by: Xiangwei Li <liwei728@xxxxxxxxxx> Signed-off-by: Xiongfeng Wang <wangxiongfeng2@xxxxxxxxxx> --- drivers/pci/probe.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 364fa2a514f8..8595d41add09 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -957,7 +957,6 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge) resource_size_t offset, next_offset; LIST_HEAD(resources); struct resource *res, *next_res; - bool bus_registered = false; char addr[64], *fmt; const char *name; int err; @@ -1021,7 +1020,6 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge) name = dev_name(&bus->dev); err = device_register(&bus->dev); - bus_registered = true; if (err) goto unregister; @@ -1110,15 +1108,12 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge) unregister: put_device(&bridge->dev); device_del(&bridge->dev); + free: #ifdef CONFIG_PCI_DOMAINS_GENERIC pci_bus_release_domain_nr(parent, bus->domain_nr); #endif - if (bus_registered) - put_device(&bus->dev); - else - kfree(bus); - + kfree(bus); return err; } -- 2.25.1