* [PATCH] omap-cpufreq: Fix regulator resource leak in probe()
@ 2025-12-15 3:03 Haotian Zhang
2026-01-05 5:16 ` Viresh Kumar
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Haotian Zhang @ 2025-12-15 3:03 UTC (permalink / raw)
To: Kevin Hilman, Rafael J . Wysocki, Viresh Kumar
Cc: linux-omap, linux-pm, linux-kernel, Haotian Zhang
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, leading to a potential resource leak.
Use devm_regulator_get() instead of regulator_get() so that the regulator
resource is automatically released.
Fixes: 53dfe8a884e6 ("cpufreq: OMAP: scale voltage along with frequency")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
drivers/cpufreq/omap-cpufreq.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/cpufreq/omap-cpufreq.c b/drivers/cpufreq/omap-cpufreq.c
index bbb01d93b54b..f83f85996b36 100644
--- a/drivers/cpufreq/omap-cpufreq.c
+++ b/drivers/cpufreq/omap-cpufreq.c
@@ -157,7 +157,7 @@ static int omap_cpufreq_probe(struct platform_device *pdev)
return -EINVAL;
}
- mpu_reg = regulator_get(mpu_dev, "vcc");
+ mpu_reg = devm_regulator_get(mpu_dev, "vcc");
if (IS_ERR(mpu_reg)) {
pr_warn("%s: unable to get MPU regulator\n", __func__);
mpu_reg = NULL;
@@ -169,7 +169,6 @@ static int omap_cpufreq_probe(struct platform_device *pdev)
if (regulator_get_voltage(mpu_reg) < 0) {
pr_warn("%s: physical regulator not present for MPU\n",
__func__);
- regulator_put(mpu_reg);
mpu_reg = NULL;
}
}
--
2.50.1.windows.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH] omap-cpufreq: Fix regulator resource leak in probe()
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-05 13:12 ` [PATCH v2] cpufreq: OMAP: Fix resource leak in probe error path and remove Haotian Zhang
2 siblings, 0 replies; 9+ messages in thread
From: Viresh Kumar @ 2026-01-05 5:16 UTC (permalink / raw)
To: Kevin Hilman, Haotian Zhang
Cc: Rafael J . Wysocki, linux-omap, linux-pm, linux-kernel
On 15-12-25, 11:03, Haotian Zhang wrote:
> 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, leading to a potential resource leak.
>
> Use devm_regulator_get() instead of regulator_get() so that the regulator
> resource is automatically released.
>
> Fixes: 53dfe8a884e6 ("cpufreq: OMAP: scale voltage along with frequency")
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> ---
> drivers/cpufreq/omap-cpufreq.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/cpufreq/omap-cpufreq.c b/drivers/cpufreq/omap-cpufreq.c
> index bbb01d93b54b..f83f85996b36 100644
> --- a/drivers/cpufreq/omap-cpufreq.c
> +++ b/drivers/cpufreq/omap-cpufreq.c
> @@ -157,7 +157,7 @@ static int omap_cpufreq_probe(struct platform_device *pdev)
> return -EINVAL;
> }
>
> - mpu_reg = regulator_get(mpu_dev, "vcc");
> + mpu_reg = devm_regulator_get(mpu_dev, "vcc");
> if (IS_ERR(mpu_reg)) {
> pr_warn("%s: unable to get MPU regulator\n", __func__);
> mpu_reg = NULL;
> @@ -169,7 +169,6 @@ static int omap_cpufreq_probe(struct platform_device *pdev)
> if (regulator_get_voltage(mpu_reg) < 0) {
> pr_warn("%s: physical regulator not present for MPU\n",
> __func__);
> - regulator_put(mpu_reg);
> mpu_reg = NULL;
> }
> }
Kevin ?
--
viresh
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] omap-cpufreq: Fix regulator resource leak in probe()
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-05 13:12 ` [PATCH v2] cpufreq: OMAP: Fix resource leak in probe error path and remove Haotian Zhang
2 siblings, 1 reply; 9+ messages in thread
From: Andreas Kemnade @ 2026-01-05 9:14 UTC (permalink / raw)
To: Haotian Zhang
Cc: Kevin Hilman, Rafael J . Wysocki, Viresh Kumar, linux-omap,
linux-pm, linux-kernel
On Mon, 15 Dec 2025 11:03:27 +0800
Haotian Zhang <vulab@iscas.ac.cn> wrote:
> 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, leading to a potential resource leak.
>
> Use devm_regulator_get() instead of regulator_get() so that the regulator
> resource is automatically released.
>
> Fixes: 53dfe8a884e6 ("cpufreq: OMAP: scale voltage along with frequency")
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> ---
> drivers/cpufreq/omap-cpufreq.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/cpufreq/omap-cpufreq.c b/drivers/cpufreq/omap-cpufreq.c
> index bbb01d93b54b..f83f85996b36 100644
> --- a/drivers/cpufreq/omap-cpufreq.c
> +++ b/drivers/cpufreq/omap-cpufreq.c
> @@ -157,7 +157,7 @@ static int omap_cpufreq_probe(struct platform_device *pdev)
> return -EINVAL;
> }
>
> - mpu_reg = regulator_get(mpu_dev, "vcc");
> + mpu_reg = devm_regulator_get(mpu_dev, "vcc");
> if (IS_ERR(mpu_reg)) {
> pr_warn("%s: unable to get MPU regulator\n", __func__);
> mpu_reg = NULL;
> @@ -169,7 +169,6 @@ static int omap_cpufreq_probe(struct platform_device *pdev)
> if (regulator_get_voltage(mpu_reg) < 0) {
> pr_warn("%s: physical regulator not present for MPU\n",
> __func__);
> - regulator_put(mpu_reg);
so it it not useable and could be released which is not done anymare
with your patch. It is not an error path here.
> mpu_reg = NULL;
And this should happen after removal, too. I feel some discomfort with
variables pointing to freed ressources. So I think rather add
the regulator_put and the = NULL to the remove function.
Regards,
Andreas
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] omap-cpufreq: Fix regulator resource leak in probe()
2026-01-05 9:14 ` Andreas Kemnade
@ 2026-01-06 4:50 ` Viresh Kumar
2026-01-06 17:29 ` Andreas Kemnade
0 siblings, 1 reply; 9+ messages in thread
From: Viresh Kumar @ 2026-01-06 4:50 UTC (permalink / raw)
To: Andreas Kemnade
Cc: Haotian Zhang, Kevin Hilman, Rafael J . Wysocki, linux-omap,
linux-pm, linux-kernel
On 05-01-26, 10:14, Andreas Kemnade wrote:
> On Mon, 15 Dec 2025 11:03:27 +0800
> Haotian Zhang <vulab@iscas.ac.cn> wrote:
>
> > 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, leading to a potential resource leak.
> >
> > Use devm_regulator_get() instead of regulator_get() so that the regulator
> > resource is automatically released.
> >
> > Fixes: 53dfe8a884e6 ("cpufreq: OMAP: scale voltage along with frequency")
> > Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> > ---
> > drivers/cpufreq/omap-cpufreq.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/cpufreq/omap-cpufreq.c b/drivers/cpufreq/omap-cpufreq.c
> > index bbb01d93b54b..f83f85996b36 100644
> > --- a/drivers/cpufreq/omap-cpufreq.c
> > +++ b/drivers/cpufreq/omap-cpufreq.c
> > @@ -157,7 +157,7 @@ static int omap_cpufreq_probe(struct platform_device *pdev)
> > return -EINVAL;
> > }
> >
> > - mpu_reg = regulator_get(mpu_dev, "vcc");
> > + mpu_reg = devm_regulator_get(mpu_dev, "vcc");
> > if (IS_ERR(mpu_reg)) {
> > pr_warn("%s: unable to get MPU regulator\n", __func__);
> > mpu_reg = NULL;
> > @@ -169,7 +169,6 @@ static int omap_cpufreq_probe(struct platform_device *pdev)
> > if (regulator_get_voltage(mpu_reg) < 0) {
> > pr_warn("%s: physical regulator not present for MPU\n",
> > __func__);
> > - regulator_put(mpu_reg);
>
> so it it not useable and could be released which is not done anymare
> with your patch. It is not an error path here.
Right. Perhaps devm_regulator_put() here would be good enough.
> > mpu_reg = NULL;
>
> And this should happen after removal, too. I feel some discomfort with
> variables pointing to freed ressources. So I think rather add
> the regulator_put and the = NULL to the remove function.
I don't see a reason why this extra step should be performed after the driver is
removed. `mpu_reg` can't be used after that.
--
viresh
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] omap-cpufreq: Fix regulator resource leak in probe()
2026-01-06 4:50 ` Viresh Kumar
@ 2026-01-06 17:29 ` Andreas Kemnade
2026-01-07 5:57 ` Viresh Kumar
0 siblings, 1 reply; 9+ messages in thread
From: Andreas Kemnade @ 2026-01-06 17:29 UTC (permalink / raw)
To: Viresh Kumar
Cc: Haotian Zhang, Kevin Hilman, Rafael J . Wysocki, linux-omap,
linux-pm, linux-kernel
On Tue, 6 Jan 2026 10:20:55 +0530
Viresh Kumar <viresh.kumar@linaro.org> wrote:
> On 05-01-26, 10:14, Andreas Kemnade wrote:
> > On Mon, 15 Dec 2025 11:03:27 +0800
> > Haotian Zhang <vulab@iscas.ac.cn> wrote:
> >
> > > 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, leading to a potential resource leak.
> > >
> > > Use devm_regulator_get() instead of regulator_get() so that the regulator
> > > resource is automatically released.
> > >
> > > Fixes: 53dfe8a884e6 ("cpufreq: OMAP: scale voltage along with frequency")
> > > Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> > > ---
> > > drivers/cpufreq/omap-cpufreq.c | 3 +--
> > > 1 file changed, 1 insertion(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/cpufreq/omap-cpufreq.c b/drivers/cpufreq/omap-cpufreq.c
> > > index bbb01d93b54b..f83f85996b36 100644
> > > --- a/drivers/cpufreq/omap-cpufreq.c
> > > +++ b/drivers/cpufreq/omap-cpufreq.c
> > > @@ -157,7 +157,7 @@ static int omap_cpufreq_probe(struct platform_device *pdev)
> > > return -EINVAL;
> > > }
> > >
> > > - mpu_reg = regulator_get(mpu_dev, "vcc");
> > > + mpu_reg = devm_regulator_get(mpu_dev, "vcc");
> > > if (IS_ERR(mpu_reg)) {
> > > pr_warn("%s: unable to get MPU regulator\n", __func__);
> > > mpu_reg = NULL;
> > > @@ -169,7 +169,6 @@ static int omap_cpufreq_probe(struct platform_device *pdev)
> > > if (regulator_get_voltage(mpu_reg) < 0) {
> > > pr_warn("%s: physical regulator not present for MPU\n",
> > > __func__);
> > > - regulator_put(mpu_reg);
> >
> > so it it not useable and could be released which is not done anymare
> > with your patch. It is not an error path here.
>
> Right. Perhaps devm_regulator_put() here would be good enough.
>
ok, didn't expect such a function, so that should be the cleanest approach.
> > > mpu_reg = NULL;
> >
> > And this should happen after removal, too. I feel some discomfort with
> > variables pointing to freed ressources. So I think rather add
> > the regulator_put and the = NULL to the remove function.
>
> I don't see a reason why this extra step should be performed after the driver is
> removed. `mpu_reg` can't be used after that.
>
hmm, it is performed when the device is removed/unbound, which does not necessarily
mean the driver is removed. But that does not prevent trouble if something
is still trying to access stuff here after driver removal. So it is not really
helpful.
Hmm, how does a device gets bound to this driver?
Lets gets back to this very basic question. I am usually using CPUFREQ_DT.
Are there any signs of usage of this driver?
omap2plus_defconfig creates in .config
#
# CPU frequency scaling drivers
#
CONFIG_CPUFREQ_DT=m
# CONFIG_CPUFREQ_VIRT is not set
CONFIG_CPUFREQ_DT_PLATDEV=y
# CONFIG_ARM_OMAP2PLUS_CPUFREQ is not set
CONFIG_ARM_TI_CPUFREQ=y
# end of CPU Frequency scaling
So this thing is not used. Everything with omap2plus uses devicetree,
so probably no user at all for it. So I think we can deorbit the whole
thing.
But the fix is good for stable. So I would propose to add this
fix (to let it propagate to stable) and deorbit this driver.
Regards,
Andreas
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] omap-cpufreq: Fix regulator resource leak in probe()
2026-01-06 17:29 ` Andreas Kemnade
@ 2026-01-07 5:57 ` Viresh Kumar
2026-01-07 7:58 ` Andreas Kemnade
0 siblings, 1 reply; 9+ messages in thread
From: Viresh Kumar @ 2026-01-07 5:57 UTC (permalink / raw)
To: Andreas Kemnade, Nishanth Menon, Kevin Hilman
Cc: Haotian Zhang, Rafael J . Wysocki, linux-omap, linux-pm,
linux-kernel
On 06-01-26, 18:29, Andreas Kemnade wrote:
> hmm, it is performed when the device is removed/unbound, which does not necessarily
> mean the driver is removed.
For the cpufreq drivers, the device is normally never removed. It either gets
created from DT or some platform specific code creates the device for ever. But
anyway, we were both talking about unbound being called, doesn't matter if it is
the device or driver which is removed.
> But that does not prevent trouble if something
> is still trying to access stuff here after driver removal. So it is not really
> helpful.
It is not possible for something to still be using the resources from this
driver (like the global variables) after remove() is called. If there is a bug
in there, then that needs to be fixed instead.
> Hmm, how does a device gets bound to this driver?
Nice catch.
Tried to look at history.
commit cb6675d6a868 ("ARM: OMAP2+: Remove legacy PM init")
This commit removed the platform device being created and mentions that stuff
happens via DT, which AFAIU, creates the cpufreq-dt device instead.
So no one should be using this driver since year 2016.
Kevin, Nishanth, can you please confirm ? We should remove this driver.
> But the fix is good for stable. So I would propose to add this
> fix (to let it propagate to stable) and deorbit this driver.
I don't think it is worth adding to stable when there are no users.
--
viresh
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] omap-cpufreq: Fix regulator resource leak in probe()
2026-01-07 5:57 ` Viresh Kumar
@ 2026-01-07 7:58 ` Andreas Kemnade
0 siblings, 0 replies; 9+ messages in thread
From: Andreas Kemnade @ 2026-01-07 7:58 UTC (permalink / raw)
To: Viresh Kumar
Cc: Nishanth Menon, Kevin Hilman, Haotian Zhang, Rafael J . Wysocki,
linux-omap, linux-pm, linux-kernel
On Wed, 7 Jan 2026 11:27:42 +0530
Viresh Kumar <viresh.kumar@linaro.org> wrote:
> > But the fix is good for stable. So I would propose to add this
> > fix (to let it propagate to stable) and deorbit this driver.
>
> I don't think it is worth adding to stable when there are no users.
ok, thet commit is from v4.9, oldest longterm is 5.10.
So also no users in longterm kernels, so we do not need the fix at all.
Regards,
Andreas
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] cpufreq: OMAP: Fix resource leak in probe error path and remove
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-05 13:12 ` Haotian Zhang
2026-01-06 4:51 ` Viresh Kumar
2 siblings, 1 reply; 9+ messages in thread
From: Haotian Zhang @ 2026-01-05 13:12 UTC (permalink / raw)
To: andreas, khilman, rafael, viresh.kumar
Cc: linux-omap, linux-pm, linux-kernel, Haotian Zhang
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
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v2] cpufreq: OMAP: Fix resource leak in probe error path and remove
2026-01-05 13:12 ` [PATCH v2] cpufreq: OMAP: Fix resource leak in probe error path and remove Haotian Zhang
@ 2026-01-06 4:51 ` Viresh Kumar
0 siblings, 0 replies; 9+ messages in thread
From: Viresh Kumar @ 2026-01-06 4:51 UTC (permalink / raw)
To: Haotian Zhang
Cc: andreas, khilman, rafael, linux-omap, linux-pm, linux-kernel
On 05-01-26, 21:12, Haotian Zhang wrote:
> 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(-)
I have left some feedback on the previous version. Lets continue the discussion
there.
--
viresh
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-01-07 7:58 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v2] cpufreq: OMAP: Fix resource leak in probe error path and remove Haotian Zhang
2026-01-06 4:51 ` Viresh Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox