提交 1c78217f 编写于 作者: N Nishanth Menon 提交者: Kevin Hilman

cpufreq: OMAP: fix freq_table leak

We use a single frequency table for multiple CPUs. But, with
OMAP4, since we have multiple CPUs, the cpu_init call for CPU1
causes freq_table previously allocated for CPU0 to be overwritten.
In addition, we dont free the table on exit path.

We solve this by maintaining an atomic type counter to ensure
just a single table exists at a given time.
Signed-off-by: NNishanth Menon <nm@ti.com>
Signed-off-by: NKevin Hilman <khilman@ti.com>
上级 11e04fdd
...@@ -46,6 +46,7 @@ static struct lpj_info global_lpj_ref; ...@@ -46,6 +46,7 @@ static struct lpj_info global_lpj_ref;
#endif #endif
static struct cpufreq_frequency_table *freq_table; static struct cpufreq_frequency_table *freq_table;
static atomic_t freq_table_users = ATOMIC_INIT(0);
static struct clk *mpu_clk; static struct clk *mpu_clk;
static char *mpu_clk_name; static char *mpu_clk_name;
static struct device *mpu_dev; static struct device *mpu_dev;
...@@ -150,6 +151,12 @@ static int omap_target(struct cpufreq_policy *policy, ...@@ -150,6 +151,12 @@ static int omap_target(struct cpufreq_policy *policy,
return ret; return ret;
} }
static inline void freq_table_free(void)
{
if (atomic_dec_and_test(&freq_table_users))
opp_free_cpufreq_table(mpu_dev, &freq_table);
}
static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy) static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
{ {
int result = 0; int result = 0;
...@@ -164,7 +171,9 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy) ...@@ -164,7 +171,9 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
} }
policy->cur = policy->min = policy->max = omap_getspeed(policy->cpu); policy->cur = policy->min = policy->max = omap_getspeed(policy->cpu);
result = opp_init_cpufreq_table(mpu_dev, &freq_table);
if (atomic_inc_return(&freq_table_users) == 1)
result = opp_init_cpufreq_table(mpu_dev, &freq_table);
if (result) { if (result) {
dev_err(mpu_dev, "%s: cpu%d: failed creating freq table[%d]\n", dev_err(mpu_dev, "%s: cpu%d: failed creating freq table[%d]\n",
...@@ -173,10 +182,10 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy) ...@@ -173,10 +182,10 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
} }
result = cpufreq_frequency_table_cpuinfo(policy, freq_table); result = cpufreq_frequency_table_cpuinfo(policy, freq_table);
if (!result) if (result)
cpufreq_frequency_table_get_attr(freq_table, policy->cpu); goto fail_table;
else
goto fail_ck; cpufreq_frequency_table_get_attr(freq_table, policy->cpu);
policy->min = policy->cpuinfo.min_freq; policy->min = policy->cpuinfo.min_freq;
policy->max = policy->cpuinfo.max_freq; policy->max = policy->cpuinfo.max_freq;
...@@ -199,6 +208,8 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy) ...@@ -199,6 +208,8 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
return 0; return 0;
fail_table:
freq_table_free();
fail_ck: fail_ck:
clk_put(mpu_clk); clk_put(mpu_clk);
return result; return result;
...@@ -206,6 +217,7 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy) ...@@ -206,6 +217,7 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
static int omap_cpu_exit(struct cpufreq_policy *policy) static int omap_cpu_exit(struct cpufreq_policy *policy)
{ {
freq_table_free();
clk_put(mpu_clk); clk_put(mpu_clk);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册