[PATCH v3] soc: dove: fix OF node leaks in dove_init_pmu()

zhaofeng2 zhaofeng2 at cmss.chinamobile.com
Mon Nov 30 17:59:49 PST 2026


From: Zhao Feng <zhaofeng2 at cmss.chinamobile.com>

dove_init_pmu() takes two OF node references: np_pmu via
of_find_compatible_node() and domains_node via of_get_child_by_name().
On success np_pmu is transferred to the long-lived pmu_data
(pmu->of_node), but several paths leak references:

- missing domains node: np_pmu is leaked;
- pmu allocation failure: np_pmu and domains_node are leaked;
- of_iomap() failure: both are leaked (pmu is freed, dropping the
  only holder of the np_pmu reference);
- success: domains_node is never released after the child-node
  loop.

Drop the references on all these paths.  The np_pmu reference on the
success path stays with pmu->of_node, which lives for the lifetime
of the system.

Signed-off-by: Zhao Feng <zhaofeng2 at cmss.chinamobile.com>
---
v3: drop the Fixes tag per Andrew Lunn - this is a one-time
    __init-time leak of a few node references, not worth a stable
    backport.
v2: rework against current upstream master, which restructured the
    driver since v1 was written (kzalloc_obj(), scoped child-node
    iterator); the leaks themselves are unchanged.  Also fixes the
    odd trailing hunk Andrew noted in v1 - the of_node_put() is now
    a plain insertion before "return 0".

Verified against current upstream master.  Leak found by code
inspection (OF reference-counting audit of dove_init_pmu()).

 drivers/soc/dove/pmu.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

--- a/drivers/soc/dove/pmu.c
+++ b/drivers/soc/dove/pmu.c
@@ -383,12 +383,16 @@ int __init dove_init_pmu(void)
 	domains_node = of_get_child_by_name(np_pmu, "domains");
 	if (!domains_node) {
 		pr_err("%pOFn: failed to find domains sub-node\n", np_pmu);
+		of_node_put(np_pmu);
 		return 0;
 	}
 
 	pmu = kzalloc_obj(*pmu);
-	if (!pmu)
+	if (!pmu) {
+		of_node_put(domains_node);
+		of_node_put(np_pmu);
 		return -ENOMEM;
+	}
 
 	spin_lock_init(&pmu->lock);
 	pmu->of_node = np_pmu;
@@ -399,6 +404,8 @@ int __init dove_init_pmu(void)
 		iounmap(pmu->pmu_base);
 		iounmap(pmu->pmc_base);
 		kfree(pmu);
+		of_node_put(domains_node);
+		of_node_put(np_pmu);
 		return -ENOMEM;
 	}
 
@@ -450,5 +457,7 @@ int __init dove_init_pmu(void)
 			pr_err("dove_init_pmu_irq() failed: %d\n", ret);
 	}
 
+	of_node_put(domains_node);
+
 	return 0;
 }





More information about the linux-arm-kernel mailing list