PCI: fix reference leak in pci_register_host_bridge()
Subsystems (2)
PATCH RESEND v2 1/1 PCI: fix reference leak in pci_register_host_bridge()
Once device_register() failed, we should call put_device() to decrement reference count for cleanup. Or it could cause memory leak.
device_register() includes device_add(). As comment of device_add() says, 'if device_add() succeeds, you should call device_del() when you want to get rid of it. If device_add() has not succeeded, use only put_device() to drop the reference count'.
Found by code review.
---
Changes in v2:
- modified the patch description.
--- drivers/pci/probe.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/probe.c +3 -1
@@ -1018,8 +1018,10 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge) name =dev_name (&bus->dev); err =device_register (&bus->dev); -if (err) +if (err) { +put_device (&bus->dev); goto unregister; + }pcibios_add_bus (bus);
Signature · 1 line
2.25.1
Bjorn Helgaas
AppliedQuoted 8 lines · Ma Ke
Once
device_register()failed, we should callput_device()to decrement reference count for cleanup. Or it could cause memory leak.
device_register()includesdevice_add(). As comment ofdevice_add()says, 'ifdevice_add()succeeds, you should calldevice_del()when you want to get rid of it. Ifdevice_add()has not succeeded, use onlyput_device()to drop the reference count'.
Quoted 5 lines
Found by code review.
Fixes 37d6a0a6f470 ("PCI: Add pci_register_host_bridge() interface")Signed-off-by Ma Ke <[email protected]>
Applied to pci/enumeration for v6.15, thanks!
Quoted 26 lines
---
Changes in v2:
- modified the patch description.--- drivers/pci/probe.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/pci/probe.c +3
-1@@ -1018,8 +1018,10 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge) name =dev_name (&bus->dev); err =device_register (&bus->dev); -if (err) +if (err) { +put_device (&bus->dev); goto unregister; + }pcibios_add_bus (bus);Signature · 1 line
2.25.1