[PATCH] platform/x86: pmc_atom: Fix PCI device reference leak in pmc_atom_init()

From: Wentao Liang

Date: Thu Sep 17 2026 - 10:30:40 EST


pmc_atom_init() iterates over the PCI devices with for_each_pci_dev()
and returns pmc_setup_dev()'s result directly from inside the loop when
a matching device is found. The reference obtained for the matched
device by pci_get_device() (via for_each_pci_dev()) is never dropped,
leaking a reference to the PCI device on every successful init.

Break out of the loop, drop the reference with pci_dev_put() before
returning, as pci_dev_put() on a NULL pointer is a no-op when no device
was matched.

Fixes: 2b8f8eddaf05 ("x86/platform/intel/pmc_atom: Add Cherrytrail PMC interface")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/platform/x86/pmc_atom.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/pmc_atom.c b/drivers/platform/x86/pmc_atom.c
index 48c2a0e59d18..750b72c6c616 100644
--- a/drivers/platform/x86/pmc_atom.c
+++ b/drivers/platform/x86/pmc_atom.c
@@ -579,6 +579,7 @@ static int __init pmc_atom_init(void)
{
struct pci_dev *pdev = NULL;
const struct pci_device_id *ent;
+ int ret = -ENODEV;

/*
* We look for our device - PCU PMC.
@@ -591,11 +592,14 @@ static int __init pmc_atom_init(void)
*/
for_each_pci_dev(pdev) {
ent = pci_match_id(pmc_pci_ids, pdev);
- if (ent)
- return pmc_setup_dev(pdev, ent);
+ if (ent) {
+ ret = pmc_setup_dev(pdev, ent);
+ break;
+ }
}
- /* Device not found */
- return -ENODEV;
+
+ pci_dev_put(pdev);
+ return ret;
}

device_initcall(pmc_atom_init);
--
2.34.1