Commit 42913c79 authored by Julia Lawall's avatar Julia Lawall Committed by Ralf Baechle

MIPS: Loongson2: Use clk API instead of direct dereferences

A struct clk value is intended to be an abstract pointer, so it should be
manipulated using the various API functions.

clk_put is additionally added on the failure paths.

The semantic match that finds the first problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression e,e1;
identifier i;
@@

*e = clk_get(...)
 ... when != e = e1
     when any
*e->i
// </smpl>
Signed-off-by: default avatarJulia Lawall <Julia.Lawall@lip6.fr>
Cc: kernel-janitors@vger.kernel.org
Cc: linux-mips@linux-mips.org,
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/4751/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent 0f3a05cb
...@@ -107,6 +107,8 @@ static int loongson2_cpufreq_target(struct cpufreq_policy *policy, ...@@ -107,6 +107,8 @@ static int loongson2_cpufreq_target(struct cpufreq_policy *policy,
static int loongson2_cpufreq_cpu_init(struct cpufreq_policy *policy) static int loongson2_cpufreq_cpu_init(struct cpufreq_policy *policy)
{ {
int i; int i;
unsigned long rate;
int ret;
if (!cpu_online(policy->cpu)) if (!cpu_online(policy->cpu))
return -ENODEV; return -ENODEV;
...@@ -117,15 +119,22 @@ static int loongson2_cpufreq_cpu_init(struct cpufreq_policy *policy) ...@@ -117,15 +119,22 @@ static int loongson2_cpufreq_cpu_init(struct cpufreq_policy *policy)
return PTR_ERR(cpuclk); return PTR_ERR(cpuclk);
} }
cpuclk->rate = cpu_clock_freq / 1000; rate = cpu_clock_freq / 1000;
if (!cpuclk->rate) if (!rate) {
clk_put(cpuclk);
return -EINVAL; return -EINVAL;
}
ret = clk_set_rate(cpuclk, rate);
if (ret) {
clk_put(cpuclk);
return ret;
}
/* clock table init */ /* clock table init */
for (i = 2; for (i = 2;
(loongson2_clockmod_table[i].frequency != CPUFREQ_TABLE_END); (loongson2_clockmod_table[i].frequency != CPUFREQ_TABLE_END);
i++) i++)
loongson2_clockmod_table[i].frequency = (cpuclk->rate * i) / 8; loongson2_clockmod_table[i].frequency = (rate * i) / 8;
policy->cur = loongson2_cpufreq_get(policy->cpu); policy->cur = loongson2_cpufreq_get(policy->cpu);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment