]> www.infradead.org Git - users/hch/misc.git/commitdiff
PCI/pwrctrl: Fix device and OF node leak at bus scan
authorJohan Hovold <johan+linaro@kernel.org>
Mon, 21 Jul 2025 15:36:08 +0000 (17:36 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 27 Aug 2025 19:32:11 +0000 (14:32 -0500)
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: 957f40d039a9 ("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
drivers/pci/probe.c

index f41128f91ca76ab014ad669ae84a53032c7c6b6b..a56dfa1c9b6ffe2bf5b5b48c4881cf41012cf755 100644 (file)
@@ -2516,9 +2516,15 @@ static struct platform_device *pci_pwrctrl_create_device(struct pci_bus *bus, in
        struct device_node *np;
 
        np = of_pci_find_child_device(dev_of_node(&bus->dev), devfn);
-       if (!np || of_find_device_by_node(np))
+       if (!np)
                return NULL;
 
+       pdev = of_find_device_by_node(np);
+       if (pdev) {
+               put_device(&pdev->dev);
+               goto err_put_of_node;
+       }
+
        /*
         * First check whether the pwrctrl device really needs to be created or
         * not. This is decided based on at least one of the power supplies
@@ -2526,17 +2532,24 @@ static struct platform_device *pci_pwrctrl_create_device(struct pci_bus *bus, in
         */
        if (!of_pci_supply_present(np)) {
                pr_debug("PCI/pwrctrl: Skipping OF node: %s\n", np->name);
-               return NULL;
+               goto err_put_of_node;
        }
 
        /* Now create the pwrctrl device */
        pdev = of_platform_device_create(np, NULL, &host->dev);
        if (!pdev) {
                pr_err("PCI/pwrctrl: Failed to create pwrctrl device for node: %s\n", np->name);
-               return NULL;
+               goto err_put_of_node;
        }
 
+       of_node_put(np);
+
        return pdev;
+
+err_put_of_node:
+       of_node_put(np);
+
+       return NULL;
 }
 #else
 static struct platform_device *pci_pwrctrl_create_device(struct pci_bus *bus, int devfn)