]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
cpufreq: s5pv210: fix refcount leak
authorShuhao Fu <sfual@cse.ust.hk>
Sun, 5 Oct 2025 19:31:17 +0000 (03:31 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Jan 2026 12:09:42 +0000 (13:09 +0100)
[ Upstream commit 2de5cb96060a1664880d65b120e59485a73588a8 ]

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>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/cpufreq/s5pv210-cpufreq.c

index ad7d4f272ddcb525b8e7abebd8dda1a1bcf2aa39..f51b2e84ef63d55cb8e8b85850f3a171a923099d 100644 (file)
@@ -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: