diff mbox

[PM-WIP_CPUFREQ,V3,5/8] OMAP2+: cpufreq: fix invalid cpufreq table with central alloc/free

Message ID 1306366733-8439-6-git-send-email-nm@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Nishanth Menon May 25, 2011, 11:38 p.m. UTC
By creating freq_table_[alloc|free] we can handle the differences
between OMAP2 and OMAP3+ systems and we have a centralized allocation
and cleanup strategy. We use this to cleanup the freq_table when
cpufreq_frequency_table_cpuinfo fails.

Signed-off-by: Nishanth Menon <nm@ti.com>
---
 arch/arm/mach-omap2/omap2plus-cpufreq.c |   48 +++++++++++++++++++++---------
 1 files changed, 33 insertions(+), 15 deletions(-)

Comments

Todd Poynor May 26, 2011, 1:09 a.m. UTC | #1
On Wed, May 25, 2011 at 04:38:50PM -0700, Nishanth Menon wrote:
> By creating freq_table_[alloc|free] we can handle the differences
> between OMAP2 and OMAP3+ systems and we have a centralized allocation
> and cleanup strategy. We use this to cleanup the freq_table when
> cpufreq_frequency_table_cpuinfo fails.
> 
> Signed-off-by: Nishanth Menon <nm@ti.com>
> ---
...
>  static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
>  {
>  	int result = 0;
> @@ -167,21 +187,22 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
>  		return -EINVAL;
>  
>  	policy->cur = policy->min = policy->max = omap_getspeed(policy->cpu);
> -	if (use_opp)
> -		opp_init_cpufreq_table(mpu_dev, &freq_table);
> -	else
> -		clk_init_cpufreq_table(&freq_table);
>  
> -	if (!freq_table) {
> -		dev_err(mpu_dev, "%s: cpu%d: unable to allocate freq table\n",
> -				__func__, policy->cpu);
> -		return -ENOMEM;
> +	result = freq_table_alloc();
> +	if (result || !freq_table) {
> +		dev_err(mpu_dev, "%s: cpu%d: unable to get freq table [%d]\n",
> +			__func__, policy->cpu, result);
> +		return result;

The "|| !freq_table" isn't needed, and technically allows the code to
return zero for an error return if the subexpression does evaluate
true.


Todd
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Nishanth Menon May 26, 2011, 1:21 a.m. UTC | #2
On Wed, May 25, 2011 at 18:09, Todd Poynor <toddpoynor@google.com> wrote:
>> +     if (result || !freq_table) {
>> +             dev_err(mpu_dev, "%s: cpu%d: unable to get freq table [%d]\n",
>> +                     __func__, policy->cpu, result);
>> +             return result;
>
> The "|| !freq_table" isn't needed, and technically allows the code to
> return zero for an error return if the subexpression does evaluate
> true.
>
Ack..


Regards,
Nishanth Menon
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/arch/arm/mach-omap2/omap2plus-cpufreq.c b/arch/arm/mach-omap2/omap2plus-cpufreq.c
index 7c0eb77..3ff3302 100644
--- a/arch/arm/mach-omap2/omap2plus-cpufreq.c
+++ b/arch/arm/mach-omap2/omap2plus-cpufreq.c
@@ -154,6 +154,26 @@  skip_lpj:
 	return ret;
 }
 
+static int freq_table_alloc(void)
+{
+	if (use_opp)
+		return opp_init_cpufreq_table(mpu_dev, &freq_table);
+
+	clk_init_cpufreq_table(&freq_table);
+	if (!freq_table)
+		return -ENOMEM;
+
+	return 0;
+}
+
+static void freq_table_free(void)
+{
+	if (use_opp)
+		opp_free_cpufreq_table(mpu_dev, &freq_table);
+	else
+		clk_exit_cpufreq_table(&freq_table);
+}
+
 static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
 {
 	int result = 0;
@@ -167,21 +187,22 @@  static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
 		return -EINVAL;
 
 	policy->cur = policy->min = policy->max = omap_getspeed(policy->cpu);
-	if (use_opp)
-		opp_init_cpufreq_table(mpu_dev, &freq_table);
-	else
-		clk_init_cpufreq_table(&freq_table);
 
-	if (!freq_table) {
-		dev_err(mpu_dev, "%s: cpu%d: unable to allocate freq table\n",
-				__func__, policy->cpu);
-		return -ENOMEM;
+	result = freq_table_alloc();
+	if (result || !freq_table) {
+		dev_err(mpu_dev, "%s: cpu%d: unable to get freq table [%d]\n",
+			__func__, policy->cpu, result);
+		return result;
 	}
 
 	result = cpufreq_frequency_table_cpuinfo(policy, freq_table);
-	if (!result)
-		cpufreq_frequency_table_get_attr(freq_table,
-						policy->cpu);
+	if (result) {
+		dev_err(mpu_dev, "%s: cpu%d: unable to get cpuinfo [%d]\n",
+			__func__, policy->cpu, result);
+		freq_table_free();
+		return result;
+	}
+	cpufreq_frequency_table_get_attr(freq_table, policy->cpu);
 
 	policy->min = policy->cpuinfo.min_freq;
 	policy->max = policy->cpuinfo.max_freq;
@@ -208,10 +229,7 @@  static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
 
 static int omap_cpu_exit(struct cpufreq_policy *policy)
 {
-	if (use_opp)
-		opp_free_cpufreq_table(mpu_dev, &freq_table);
-	else
-		clk_exit_cpufreq_table(&freq_table);
+	freq_table_free();
 	clk_put(mpu_clk);
 	return 0;
 }