Skip to content

Commit

Permalink
PCI: Fix reference leak in pci_alloc_child_bus()
Browse files Browse the repository at this point in the history
commit 1f2768b 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/20250202062357.872971-1-make24@iscas.ac.cn
Fixes: 4f53509 ("PCI: Put pci_dev in device tree as early as possible")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Ma Ke authored and Greg Kroah-Hartman committed May 2, 2025
1 parent a2319a9 commit f33c7d8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/pci/probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,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);

Expand Down

0 comments on commit f33c7d8

Please sign in to comment.