From: Haotian Zhang <vulab@iscas.ac.cn>
To: andreas@kemnade.info, khilman@kernel.org, rafael@kernel.org,
viresh.kumar@linaro.org
Cc: linux-omap@vger.kernel.org, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org, Haotian Zhang <vulab@iscas.ac.cn>
Subject: [PATCH v2] cpufreq: OMAP: Fix resource leak in probe error path and remove
Date: Mon, 5 Jan 2026 21:12:53 +0800 [thread overview]
Message-ID: <20260105131253.2692-1-vulab@iscas.ac.cn> (raw)
In-Reply-To: <20251215030327.1771-1-vulab@iscas.ac.cn>
The current omap_cpufreq_probe() uses regulator_get() to obtain the MPU
regulator but does not release it in omap_cpufreq_remove() or when
cpufreq_register_driver() fails.
Add the missing regulator_put() in the remove function and in the
error handling path of the probe function to prevent resource leaks.
Also ensure the mpu_reg pointer is set to NULL after release to avoid
dangling pointers.
Fixes: 53dfe8a884e6 ("cpufreq: OMAP: scale voltage along with frequency")
Suggested-by: Andreas Kemnade <andreas@kemnade.info>
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
Changes in v2:
- Revert to using regulator_get() instead of devm_regulator_get()
to ensure immediate release of unusable regulators and
safer handling of the global mpu_reg variable.
- Add explicit regulator_put() in omap_cpufreq_remove().
- Add error handling for cpufreq_register_driver() in probe.
---
drivers/cpufreq/omap-cpufreq.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/drivers/cpufreq/omap-cpufreq.c b/drivers/cpufreq/omap-cpufreq.c
index bbb01d93b54b..b3d58090d202 100644
--- a/drivers/cpufreq/omap-cpufreq.c
+++ b/drivers/cpufreq/omap-cpufreq.c
@@ -151,6 +151,8 @@ static struct cpufreq_driver omap_driver = {
static int omap_cpufreq_probe(struct platform_device *pdev)
{
+ int ret;
+
mpu_dev = get_cpu_device(0);
if (!mpu_dev) {
pr_warn("%s: unable to get the MPU device\n", __func__);
@@ -174,12 +176,23 @@ static int omap_cpufreq_probe(struct platform_device *pdev)
}
}
- return cpufreq_register_driver(&omap_driver);
+ ret = cpufreq_register_driver(&omap_driver);
+ if (ret) {
+ if (mpu_reg) {
+ regulator_put(mpu_reg);
+ mpu_reg = NULL;
+ }
+ }
+ return ret;
}
static void omap_cpufreq_remove(struct platform_device *pdev)
{
cpufreq_unregister_driver(&omap_driver);
+ if (mpu_reg) {
+ regulator_put(mpu_reg);
+ mpu_reg = NULL;
+ }
}
static struct platform_driver omap_cpufreq_platdrv = {
--
2.43.0
next prev parent reply other threads:[~2026-01-05 13:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-15 3:03 [PATCH] omap-cpufreq: Fix regulator resource leak in probe() Haotian Zhang
2026-01-05 5:16 ` Viresh Kumar
2026-01-05 9:14 ` Andreas Kemnade
2026-01-06 4:50 ` Viresh Kumar
2026-01-06 17:29 ` Andreas Kemnade
2026-01-07 5:57 ` Viresh Kumar
2026-01-07 7:58 ` Andreas Kemnade
2026-01-05 13:12 ` Haotian Zhang [this message]
2026-01-06 4:51 ` [PATCH v2] cpufreq: OMAP: Fix resource leak in probe error path and remove Viresh Kumar
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=20260105131253.2692-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=andreas@kemnade.info \
--cc=khilman@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--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