From: Weigang He <geoffreyhe2@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>,
Gregory Clement <gregory.clement@bootlin.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Weigang He <geoffreyhe2@gmail.com>
Subject: [PATCH] soc: dove: pmu: fix device_node refcount leaks in dove_init_pmu()
Date: Wed, 10 Jun 2026 14:15:36 +1000 [thread overview]
Message-ID: <20260610041536.2164285-1-geoffreyhe2@gmail.com> (raw)
dove_init_pmu() acquires two device_node references that are leaked on
several exit paths:
- np_pmu, from of_find_compatible_node(): leaked on the !domains_node
early return and on the !pmu allocation-failure return, both of which
occur before the reference is handed to pmu->of_node. On the iomap
failure path it has already been stored in pmu->of_node, so it must
be released via that field before pmu is freed.
- domains_node, from of_get_child_by_name(): used only as the iterator
base of for_each_available_child_of_node(), which never drops the
parent reference. It is leaked on the allocation-failure return, the
iomap-failure return and, most commonly, on the normal success path.
The success path keeps np_pmu alive deliberately: it is stored in
pmu->of_node and the pmu structure persists for the lifetime of the
system, so np_pmu is not put there.
Release np_pmu on the two early error returns and via pmu->of_node on the
iomap-failure return, and release domains_node on every path once it is
no longer needed.
Found by static analysis tool CodeQL.
Fixes: 44e259ac909f ("ARM: dove: create a proper PMU driver for power domains, PMU IRQs and resets")
Signed-off-by: Weigang He <geoffreyhe2@gmail.com>
---
drivers/soc/dove/pmu.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/soc/dove/pmu.c b/drivers/soc/dove/pmu.c
index 7bbd3f940e4d9..d8819ad50db5f 100644
--- 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(sizeof(*pmu), GFP_KERNEL);
- if (!pmu)
+ if (!pmu) {
+ of_node_put(np_pmu);
+ of_node_put(domains_node);
return -ENOMEM;
+ }
spin_lock_init(&pmu->lock);
pmu->of_node = np_pmu;
@@ -398,7 +402,9 @@ int __init dove_init_pmu(void)
pr_err("%pOFn: failed to map PMU\n", np_pmu);
iounmap(pmu->pmu_base);
iounmap(pmu->pmc_base);
+ of_node_put(pmu->of_node);
kfree(pmu);
+ of_node_put(domains_node);
return -ENOMEM;
}
@@ -443,6 +449,8 @@ int __init dove_init_pmu(void)
__pmu_domain_register(domain, np);
}
+ of_node_put(domains_node);
+
/* Loss of the interrupt controller is not a fatal error. */
parent_irq = irq_of_parse_and_map(pmu->of_node, 0);
if (!parent_irq) {
base-commit: 0f61b1860cc3f52aef9036d7235ed1f017632193
--
2.43.0
next reply other threads:[~2026-06-10 4:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-10 4:15 Weigang He [this message]
2026-06-21 19:20 ` [PATCH] soc: dove: pmu: fix device_node refcount leaks in dove_init_pmu() Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260610041536.2164285-1-geoffreyhe2@gmail.com \
--to=geoffreyhe2@gmail.com \
--cc=andrew@lunn.ch \
--cc=gregory.clement@bootlin.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sebastian.hesselbarth@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox