Skip to content

Commit 1f2768b

Browse files
Ma Kebjorn-helgaas
authored andcommitted
PCI: Fix reference leak in pci_alloc_child_bus()
If device_register(&child->dev) fails, call put_device() to explicitly release child->dev, per the comment at device_register(). Found by code review. Link: https://lore.kernel.org/r/[email protected] Fixes: 4f53509 ("PCI: Put pci_dev in device tree as early as possible") Signed-off-by: Ma Ke <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Cc: [email protected]
1 parent 804443c commit 1f2768b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/pci/probe.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,10 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
12221222
add_dev:
12231223
pci_set_bus_msi_domain(child);
12241224
ret = device_register(&child->dev);
1225-
WARN_ON(ret < 0);
1225+
if (WARN_ON(ret < 0)) {
1226+
put_device(&child->dev);
1227+
return NULL;
1228+
}
12261229

12271230
pcibios_add_bus(child);
12281231

0 commit comments

Comments
 (0)