diff options
| author | Ma Ke <make24@iscas.ac.cn> | 2025-02-02 14:23:57 +0800 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-04-20 10:18:25 +0200 |
| commit | 1bf3ccb3a731e1a7db1cb3d2f85d0decc0d2f26b (patch) | |
| tree | da471bcc18447bafd4bfd03b8179124eb2dbe78e | |
| parent | 0d0bbd01f7c0ac7d1be9f85aaf2cd0baec34655f (diff) | |
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/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>
| -rw-r--r-- | drivers/pci/probe.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index a0e24d99e43f..961760bb2d96 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1173,7 +1173,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); |
