qoriq_cpufreq_cpu_init() obtains a consumer clock with of_clk_get() and
stores it in policy->clk. If the allocation of data->pclk or of the
frequency table fails afterwards, the error paths jump to err_nomem2 or
err_pclk, which only free the allocated memory and drop the CPU node
reference; the reference obtained by of_clk_get() is never released,
leaking a clock reference on each failed init.
Add an err_clk label that releases policy->clk with clk_put() before
falling through to err_nomem2. The path on which of_clk_get() itself
fails keeps jumping straight to err_nomem2, as policy->clk is only an
error pointer there and must not be put.
Fixes: b1e9a64972bf ("cpufreq: qoriq: Don't look at clock implementation details")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <redacted>
---
drivers/cpufreq/qoriq-cpufreq.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/cpufreq/qoriq-cpufreq.c b/drivers/cpufreq/qoriq-cpufreq.c
index 42edb41ad459..13d3333e68d8 100644
--- a/drivers/cpufreq/qoriq-cpufreq.c
+++ b/drivers/cpufreq/qoriq-cpufreq.c
@@ -183,7 +183,7 @@ static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy)
data->pclk = kzalloc_objs(struct clk *, count);
if (!data->pclk)
- goto err_nomem2;
+ goto err_clk;
table = kzalloc_objs(*table, count + 1);
if (!table)
@@ -217,6 +217,8 @@ static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy)
err_pclk:
kfree(data->pclk);
+err_clk:
+ clk_put(policy->clk);
err_nomem2:
kfree(data);
err_np:
--
2.34.1