* [PATCH] cpufreq: s5pv210: fix refcount leak
@ 2025-10-05 19:31 Shuhao Fu
2025-10-06 5:23 ` Viresh Kumar
0 siblings, 1 reply; 2+ messages in thread
From: Shuhao Fu @ 2025-10-05 19:31 UTC (permalink / raw)
To: Rafael J. Wysocki, Viresh Kumar; +Cc: linux-pm
In function `s5pv210_cpu_init`, a possible refcount inconsistency has
been identified, causing a resource leak.
Why it is a bug:
1. For every clk_get, there should be a matching clk_put on every
successive error handling path.
2. After calling `clk_get(dmc1_clk)`, variable `dmc1_clk` will not be
freed even if any error happens.
How it is fixed: For every failed path, an extra goto label is added to
ensure `dmc1_clk` will be freed regardlessly.
Signed-off-by: Shuhao Fu <sfual@cse.ust.hk>
---
drivers/cpufreq/s5pv210-cpufreq.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/cpufreq/s5pv210-cpufreq.c b/drivers/cpufreq/s5pv210-cpufreq.c
index 4215621de..ba8a1c964 100644
--- a/drivers/cpufreq/s5pv210-cpufreq.c
+++ b/drivers/cpufreq/s5pv210-cpufreq.c
@@ -518,7 +518,7 @@ static int s5pv210_cpu_init(struct cpufreq_policy *policy)
if (policy->cpu != 0) {
ret = -EINVAL;
- goto out_dmc1;
+ goto out;
}
/*
@@ -530,7 +530,7 @@ static int s5pv210_cpu_init(struct cpufreq_policy *policy)
if ((mem_type != LPDDR) && (mem_type != LPDDR2)) {
pr_err("CPUFreq doesn't support this memory type\n");
ret = -EINVAL;
- goto out_dmc1;
+ goto out;
}
/* Find current refresh counter and frequency each DMC */
@@ -544,6 +544,8 @@ static int s5pv210_cpu_init(struct cpufreq_policy *policy)
cpufreq_generic_init(policy, s5pv210_freq_table, 40000);
return 0;
+out:
+ clk_put(dmc1_clk);
out_dmc1:
clk_put(dmc0_clk);
out_dmc0:
--
2.39.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] cpufreq: s5pv210: fix refcount leak
2025-10-05 19:31 [PATCH] cpufreq: s5pv210: fix refcount leak Shuhao Fu
@ 2025-10-06 5:23 ` Viresh Kumar
0 siblings, 0 replies; 2+ messages in thread
From: Viresh Kumar @ 2025-10-06 5:23 UTC (permalink / raw)
To: Shuhao Fu; +Cc: Rafael J. Wysocki, linux-pm
On 06-10-25, 03:31, Shuhao Fu wrote:
> In function `s5pv210_cpu_init`, a possible refcount inconsistency has
> been identified, causing a resource leak.
>
> Why it is a bug:
> 1. For every clk_get, there should be a matching clk_put on every
> successive error handling path.
> 2. After calling `clk_get(dmc1_clk)`, variable `dmc1_clk` will not be
> freed even if any error happens.
>
> How it is fixed: For every failed path, an extra goto label is added to
> ensure `dmc1_clk` will be freed regardlessly.
>
> Signed-off-by: Shuhao Fu <sfual@cse.ust.hk>
> ---
> drivers/cpufreq/s5pv210-cpufreq.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cpufreq/s5pv210-cpufreq.c b/drivers/cpufreq/s5pv210-cpufreq.c
> index 4215621de..ba8a1c964 100644
> --- a/drivers/cpufreq/s5pv210-cpufreq.c
> +++ b/drivers/cpufreq/s5pv210-cpufreq.c
> @@ -518,7 +518,7 @@ static int s5pv210_cpu_init(struct cpufreq_policy *policy)
>
> if (policy->cpu != 0) {
> ret = -EINVAL;
> - goto out_dmc1;
> + goto out;
> }
>
> /*
> @@ -530,7 +530,7 @@ static int s5pv210_cpu_init(struct cpufreq_policy *policy)
> if ((mem_type != LPDDR) && (mem_type != LPDDR2)) {
> pr_err("CPUFreq doesn't support this memory type\n");
> ret = -EINVAL;
> - goto out_dmc1;
> + goto out;
> }
>
> /* Find current refresh counter and frequency each DMC */
> @@ -544,6 +544,8 @@ static int s5pv210_cpu_init(struct cpufreq_policy *policy)
> cpufreq_generic_init(policy, s5pv210_freq_table, 40000);
> return 0;
>
> +out:
> + clk_put(dmc1_clk);
> out_dmc1:
> clk_put(dmc0_clk);
> out_dmc0:
Applied. Thanks.
--
viresh
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-06 5:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-05 19:31 [PATCH] cpufreq: s5pv210: fix refcount leak Shuhao Fu
2025-10-06 5:23 ` Viresh Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox