From: Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@kernel.org>
To: rafael@kernel.org, viresh.kumar@linaro.org, krzk@kernel.org,
peter.griffin@linaro.org
Cc: linux-samsung-soc@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org,
alim.akhtar@samsung.com, linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] cpufreq: kirkwood: Put clocks on error and in remove
Date: Sun, 22 Nov 2026 11:55:27 +0000 [thread overview]
Message-ID: <20261122-cpufreq-leaks-v1-2-96fc17ff7339@gmail.com> (raw)
In-Reply-To: <20261122-cpufreq-leaks-v1-0-96fc17ff7339@gmail.com>
From: Suyuan Wang <stevewong@hust.edu.cn>
kirkwood_cpufreq_probe() gets three clocks with of_clk_get_by_name():
cpu_clk, ddrclk and powersave. None of them is ever released with
clk_put(). The error paths only disable and unprepare the clocks, and
kirkwood_cpufreq_remove() does the same. So the clock references leak
when probe fails (for example on -EPROBE_DEFER) and on every unbind.
Add the missing clk_put() calls to the error paths and to remove. The
"Unable to prepare" paths now jump to new labels that only put the clock
that failed to enable.
Found with a static analysis tool and checked by hand.
Fixes: 2a4bd9f0db24 ("cpufreq: kirkwood: Add a cpufreq driver for Marvell Kirkwood SoCs")
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
drivers/cpufreq/kirkwood-cpufreq.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/cpufreq/kirkwood-cpufreq.c b/drivers/cpufreq/kirkwood-cpufreq.c
index 24b285cbeb8d..e85658081c07 100644
--- a/drivers/cpufreq/kirkwood-cpufreq.c
+++ b/drivers/cpufreq/kirkwood-cpufreq.c
@@ -125,7 +125,7 @@ static int kirkwood_cpufreq_probe(struct platform_device *pdev)
err = clk_prepare_enable(priv.cpu_clk);
if (err) {
dev_err(priv.dev, "Unable to prepare cpuclk\n");
- goto out_node;
+ goto out_put_cpu;
}
kirkwood_freq_table[0].frequency = clk_get_rate(priv.cpu_clk) / 1000;
@@ -140,7 +140,7 @@ static int kirkwood_cpufreq_probe(struct platform_device *pdev)
err = clk_prepare_enable(priv.ddr_clk);
if (err) {
dev_err(priv.dev, "Unable to prepare ddrclk\n");
- goto out_cpu;
+ goto out_put_ddr;
}
kirkwood_freq_table[1].frequency = clk_get_rate(priv.ddr_clk) / 1000;
@@ -153,7 +153,7 @@ static int kirkwood_cpufreq_probe(struct platform_device *pdev)
err = clk_prepare_enable(priv.powersave_clk);
if (err) {
dev_err(priv.dev, "Unable to prepare powersave clk\n");
- goto out_ddr;
+ goto out_put_powersave;
}
err = cpufreq_register_driver(&kirkwood_cpufreq_driver);
@@ -167,10 +167,16 @@ static int kirkwood_cpufreq_probe(struct platform_device *pdev)
out_powersave:
clk_disable_unprepare(priv.powersave_clk);
+out_put_powersave:
+ clk_put(priv.powersave_clk);
out_ddr:
clk_disable_unprepare(priv.ddr_clk);
+out_put_ddr:
+ clk_put(priv.ddr_clk);
out_cpu:
clk_disable_unprepare(priv.cpu_clk);
+out_put_cpu:
+ clk_put(priv.cpu_clk);
out_node:
of_node_put(np);
@@ -182,8 +188,11 @@ static void kirkwood_cpufreq_remove(struct platform_device *pdev)
cpufreq_unregister_driver(&kirkwood_cpufreq_driver);
clk_disable_unprepare(priv.powersave_clk);
+ clk_put(priv.powersave_clk);
clk_disable_unprepare(priv.ddr_clk);
+ clk_put(priv.ddr_clk);
clk_disable_unprepare(priv.cpu_clk);
+ clk_put(priv.cpu_clk);
}
static struct platform_driver kirkwood_cpufreq_platform_driver = {
--
2.34.1
next prev parent reply other threads:[~2026-11-22 11:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 11:55 [PATCH 0/3] cpufreq: Fix leaks on probe error paths in three drivers Suyuan Wang via B4 Relay
2026-11-22 11:55 ` [PATCH 1/3] cpufreq: highbank: Put cpu clock if clk notifier registration fails Suyuan Wang via B4 Relay
2026-11-22 11:55 ` Suyuan Wang via B4 Relay [this message]
2026-11-22 11:55 ` [PATCH 3/3] cpufreq: s5pv210: Fix resource leaks on probe error paths Suyuan Wang via B4 Relay
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=20261122-cpufreq-leaks-v1-2-96fc17ff7339@gmail.com \
--to=devnull+shyckless.gmail.com@kernel.org \
--cc=alim.akhtar@samsung.com \
--cc=krzk@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=peter.griffin@linaro.org \
--cc=rafael@kernel.org \
--cc=shyckless@gmail.com \
--cc=viresh.kumar@linaro.org \
/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
all inboxes | Powered by JetHome®