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

From: zhaofeng2

Date: Sun Nov 29 2026 - 22:38:51 EST


From: Zhao Feng <zhaofeng2@xxxxxxxxxxxxxxxxxxxx>

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.

Fixes: 44e259ac909f ("ARM: dove: create a proper PMU driver for power domains, PMU IRQs and resets")
Signed-off-by: Zhao Feng <zhaofeng2@xxxxxxxxxxxxxxxxxxxx>
---
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;
}