Skip to content

Commit e24bbbe

Browse files
jhovoldbjorn-helgaas
authored andcommitted
PCI/pwrctrl: Fix device and OF node leak at bus scan
Make sure to drop the references to the pwrctrl OF node and device taken by of_pci_find_child_device() and of_find_device_by_node() respectively when scanning the bus. Fixes: 957f40d ("PCI/pwrctrl: Move creation of pwrctrl devices to pci_scan_device()") Signed-off-by: Johan Hovold <johan+linaro@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Manivannan Sadhasivam <mani@kernel.org> Cc: stable@vger.kernel.org # v6.15 Link: https://patch.msgid.link/20250721153609.8611-3-johan+linaro@kernel.org
1 parent 39f9be6 commit e24bbbe

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

drivers/pci/probe.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,27 +2516,40 @@ static struct platform_device *pci_pwrctrl_create_device(struct pci_bus *bus, in
25162516
struct device_node *np;
25172517

25182518
np = of_pci_find_child_device(dev_of_node(&bus->dev), devfn);
2519-
if (!np || of_find_device_by_node(np))
2519+
if (!np)
25202520
return NULL;
25212521

2522+
pdev = of_find_device_by_node(np);
2523+
if (pdev) {
2524+
put_device(&pdev->dev);
2525+
goto err_put_of_node;
2526+
}
2527+
25222528
/*
25232529
* First check whether the pwrctrl device really needs to be created or
25242530
* not. This is decided based on at least one of the power supplies
25252531
* being defined in the devicetree node of the device.
25262532
*/
25272533
if (!of_pci_supply_present(np)) {
25282534
pr_debug("PCI/pwrctrl: Skipping OF node: %s\n", np->name);
2529-
return NULL;
2535+
goto err_put_of_node;
25302536
}
25312537

25322538
/* Now create the pwrctrl device */
25332539
pdev = of_platform_device_create(np, NULL, &host->dev);
25342540
if (!pdev) {
25352541
pr_err("PCI/pwrctrl: Failed to create pwrctrl device for node: %s\n", np->name);
2536-
return NULL;
2542+
goto err_put_of_node;
25372543
}
25382544

2545+
of_node_put(np);
2546+
25392547
return pdev;
2548+
2549+
err_put_of_node:
2550+
of_node_put(np);
2551+
2552+
return NULL;
25402553
}
25412554
#else
25422555
static struct platform_device *pci_pwrctrl_create_device(struct pci_bus *bus, int devfn)

0 commit comments

Comments
 (0)