From patchwork Wed May 25 23:38:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishanth Menon X-Patchwork-Id: 818762 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4PNdK0k002263 for ; Wed, 25 May 2011 23:39:20 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932190Ab1EYXjS (ORCPT ); Wed, 25 May 2011 19:39:18 -0400 Received: from na3sys009aog115.obsmtp.com ([74.125.149.238]:40224 "EHLO na3sys009aog115.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754631Ab1EYXjS (ORCPT ); Wed, 25 May 2011 19:39:18 -0400 Received: from mail-yi0-f46.google.com ([209.85.218.46]) (using TLSv1) by na3sys009aob115.postini.com ([74.125.148.12]) with SMTP ID DSNKTd2TJeaTeUU6S1c8Q7FoI+Ch9ogUbxd9@postini.com; Wed, 25 May 2011 16:39:18 PDT Received: by yia27 with SMTP id 27so92538yia.5 for ; Wed, 25 May 2011 16:39:17 -0700 (PDT) Received: by 10.91.82.7 with SMTP id j7mr280819agl.99.1306366757112; Wed, 25 May 2011 16:39:17 -0700 (PDT) Received: from localhost (dragon.ti.com [192.94.94.33]) by mx.google.com with ESMTPS id c3sm241157and.44.2011.05.25.16.39.15 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 May 2011 16:39:16 -0700 (PDT) From: Nishanth Menon To: linux-omap Cc: Kevin , Nishanth Menon Subject: [PM-WIP_CPUFREQ][PATCH V3 5/8] OMAP2+: cpufreq: fix invalid cpufreq table with central alloc/free Date: Wed, 25 May 2011 16:38:50 -0700 Message-Id: <1306366733-8439-6-git-send-email-nm@ti.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1306366733-8439-1-git-send-email-nm@ti.com> References: <1306366733-8439-1-git-send-email-nm@ti.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 25 May 2011 23:39:20 +0000 (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 --- arch/arm/mach-omap2/omap2plus-cpufreq.c | 48 +++++++++++++++++++++--------- 1 files changed, 33 insertions(+), 15 deletions(-) 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; }