From patchwork Thu Jul 21 21:39:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 72590 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp668810qga; Thu, 21 Jul 2016 14:40:00 -0700 (PDT) X-Received: by 10.98.69.201 with SMTP id n70mr667600pfi.64.1469137200798; Thu, 21 Jul 2016 14:40:00 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 123si11791959pfu.156.2016.07.21.14.39.54; Thu, 21 Jul 2016 14:40:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754601AbcGUVjd (ORCPT + 29 others); Thu, 21 Jul 2016 17:39:33 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:34383 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754416AbcGUVj3 (ORCPT ); Thu, 21 Jul 2016 17:39:29 -0400 Received: by mail-pa0-f50.google.com with SMTP id fi15so32623976pac.1 for ; Thu, 21 Jul 2016 14:39:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=gyrf2ZPSI+lnEAf/wInL9ZrIMN3k913Bh8oICWVp0Xs=; b=i/V85WSws15qxK5fdaECGihkilXhc8KfDYrjlJNNVM9IGUoUuxmstH4BGxltsEgaUX FCtDc1zcD85FSTYpFWtrZsTvCT55uqYHXbX+QSRaA6BFDMqLOtizzTPlwC3kxn8x5DmF cHCNLW1MsHUrvpoAwUzBSAeA5eQyj+wJQ5anE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=gyrf2ZPSI+lnEAf/wInL9ZrIMN3k913Bh8oICWVp0Xs=; b=Aeus1A45qWt0D4ygcYEJIZu5DXcCMiRgMPb06xaM3J/zLz0bjcC2Lwr4mJinPDsWG3 wmvemhqRR0hdtPSeDVwx5EvIS1+mrzjAJstYGZM+7YLikKzTffKClhlJII/r7ZYNmPAQ 3GvsnCIRbvv0KnN1gZPvU4tN+WbeHTypOPiTQjmJ9SCQGb58hVV6Cpcd6hMbicP2m/FD eACZV+euD22Js8m8P3+Obkt0xq5sPAP38qeZ/5m7JhPz5m88GFpk/8F74nPSnq18BxaQ 2ifTTufSY5VbYD6MO6ordrxyvIfA93sIQMoGsQ6mDhfmSD1FZkDzy5xoodI8F9T+VXo+ w40g== X-Gm-Message-State: AEkoouvNRQ/B/nJdP60tyDfJ5Mn6kMEE16upqup8iazu/FDeDp+6mJjWSL7KBFSeVzu8gzso X-Received: by 10.66.136.8 with SMTP id pw8mr644370pab.110.1469137168500; Thu, 21 Jul 2016 14:39:28 -0700 (PDT) Received: from localhost ([104.132.1.108]) by smtp.gmail.com with ESMTPSA id ya6sm14515609pab.22.2016.07.21.14.39.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jul 2016 14:39:27 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, steve.muckle@linaro.org, peterz@infradead.org, mingo@redhat.com, vincent.guittot@linaro.org, morten.rasmussen@arm.com, dietmar.eggemann@arm.com, Juri.Lelli@arm.com, patrick.bellasi@arm.com Subject: [PATCH V2] cpufreq: Disallow ->resolve_freq() for drivers providing ->target_index() Date: Thu, 21 Jul 2016 14:39:26 -0700 Message-Id: <065301260510fbca81f5481b27b0de956073068a.1469137133.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The handlers provided by cpufreq core are sufficient for resolving the frequency for drivers providing ->target_index(), as the core already has the frequency table and so ->resolve_freq() isn't required for such platforms. This patch disallows drivers with ->target_index() callback to use the ->resolve_freq() callback. Also, it fixes a potential kernel crash for drivers providing ->target() but no ->resolve_freq(). Fixes: e3c062360870 ("cpufreq: add cpufreq_driver_resolve_freq()") Signed-off-by: Viresh Kumar --- V2: - s/UINT_MAX/target_freq drivers/cpufreq/cpufreq.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index b696baeb249d..3ef9be3965ff 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -507,12 +507,20 @@ unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, { target_freq = clamp_val(target_freq, policy->min, policy->max); policy->cached_target_freq = target_freq; + + if (cpufreq_driver->target_index) { + int idx; + + idx = cpufreq_frequency_table_target(policy, target_freq, + CPUFREQ_RELATION_L); + policy->cached_resolved_idx = idx; + return policy->freq_table[idx].frequency; + } + if (cpufreq_driver->resolve_freq) return cpufreq_driver->resolve_freq(policy, target_freq); - policy->cached_resolved_idx = - cpufreq_frequency_table_target(policy, target_freq, - CPUFREQ_RELATION_L); - return policy->freq_table[policy->cached_resolved_idx].frequency; + + return target_freq; } /*********************************************************************