Skip to content

Commit 6242b5b

Browse files
Ma Kejfvogel
authored andcommitted
PCI: Fix reference leak in pci_alloc_child_bus()
commit 1f2768b6a3ee77a295106e3a5d68458064923ede upstream. 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] Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit d69ad6e1a5799b5865a50184544b9eecd526a4c0) Signed-off-by: Jack Vogel <[email protected]>
1 parent 52a7a8f commit 6242b5b

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
@@ -1171,7 +1171,10 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
11711171
add_dev:
11721172
pci_set_bus_msi_domain(child);
11731173
ret = device_register(&child->dev);
1174-
WARN_ON(ret < 0);
1174+
if (WARN_ON(ret < 0)) {
1175+
put_device(&child->dev);
1176+
return NULL;
1177+
}
11751178

11761179
pcibios_add_bus(child);
11771180

0 commit comments

Comments
 (0)