From: Ma Ke Date: Sun, 2 Feb 2025 06:23:57 +0000 (+0800) Subject: PCI: Fix reference leak in pci_alloc_child_bus() X-Git-Tag: v6.15-rc1~119^2~27^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1f2768b6a3ee77a295106e3a5d68458064923ede;p=thirdparty%2Flinux.git 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/20250202062357.872971-1-make24@iscas.ac.cn Fixes: 4f535093cf8f ("PCI: Put pci_dev in device tree as early as possible") Signed-off-by: Ma Ke Signed-off-by: Bjorn Helgaas Reviewed-by: Ilpo Järvinen Cc: stable@vger.kernel.org --- diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index dc37a3c0a9771..088131a74d7d4 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1222,7 +1222,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);