]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
PCI: Fix reference leak in pci_alloc_child_bus()
authorMa Ke <make24@iscas.ac.cn>
Sun, 2 Feb 2025 06:23:57 +0000 (14:23 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Apr 2025 08:45:36 +0000 (10:45 +0200)
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/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 <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>
drivers/pci/probe.c

index bcd1ba829e1fc187ee4484c6cf008641cea5c56c..8e5d818c29a9832855b077be32bec65945d74769 100644 (file)
@@ -1145,7 +1145,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);