]> www.infradead.org Git - users/hch/misc.git/commitdiff
PCI/pwrctrl: Fix device leak at registration
authorJohan Hovold <johan+linaro@kernel.org>
Mon, 21 Jul 2025 15:36:07 +0000 (17:36 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 27 Aug 2025 19:31:45 +0000 (14:31 -0500)
Make sure to drop the reference to the pwrctrl device taken by
of_find_device_by_node() when registering a PCI device.

Fixes: b458ff7e8176 ("PCI/pwrctl: Ensure that pwrctl drivers are probed before PCI client drivers")
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.13
Link: https://patch.msgid.link/20250721153609.8611-2-johan+linaro@kernel.org
drivers/pci/bus.c

index b77fd30bbfd9daf81d2bbc5c0d78ee2a4aa0d209..f401e296d15d2297f9dc7463b71f3e0ad621f34f 100644 (file)
@@ -361,11 +361,15 @@ void pci_bus_add_device(struct pci_dev *dev)
         * before PCI client drivers.
         */
        pdev = of_find_device_by_node(dn);
-       if (pdev && of_pci_supply_present(dn)) {
-               if (!device_link_add(&dev->dev, &pdev->dev,
-                                    DL_FLAG_AUTOREMOVE_CONSUMER))
-                       pci_err(dev, "failed to add device link to power control device %s\n",
-                               pdev->name);
+       if (pdev) {
+               if (of_pci_supply_present(dn)) {
+                       if (!device_link_add(&dev->dev, &pdev->dev,
+                                            DL_FLAG_AUTOREMOVE_CONSUMER)) {
+                               pci_err(dev, "failed to add device link to power control device %s\n",
+                                       pdev->name);
+                       }
+               }
+               put_device(&pdev->dev);
        }
 
        if (!dn || of_device_is_available(dn))