Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpufreq: s5pv210: fix refcount leak

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>

authored by

Shuhao Fu and committed by
Viresh Kumar
2de5cb96 211ddde0

+4 -2
+4 -2
drivers/cpufreq/s5pv210-cpufreq.c
··· 518 518 519 519 if (policy->cpu != 0) { 520 520 ret = -EINVAL; 521 - goto out_dmc1; 521 + goto out; 522 522 } 523 523 524 524 /* ··· 530 530 if ((mem_type != LPDDR) && (mem_type != LPDDR2)) { 531 531 pr_err("CPUFreq doesn't support this memory type\n"); 532 532 ret = -EINVAL; 533 - goto out_dmc1; 533 + goto out; 534 534 } 535 535 536 536 /* Find current refresh counter and frequency each DMC */ ··· 544 544 cpufreq_generic_init(policy, s5pv210_freq_table, 40000); 545 545 return 0; 546 546 547 + out: 548 + clk_put(dmc1_clk); 547 549 out_dmc1: 548 550 clk_put(dmc0_clk); 549 551 out_dmc0: