From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1946477AbdDYK3q (ORCPT ); Tue, 25 Apr 2017 06:29:46 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:35698 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1176469AbdDYK2m (ORCPT ); Tue, 25 Apr 2017 06:28:42 -0400 From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V4 16/17] thermal: cpu_cooling: 'freq' can't be zero in cpufreq_state2power() Date: Tue, 25 Apr 2017 15:57:23 +0530 Message-Id: <98df049ab5f1d13ebb497e922229f0e8b8160606.1493115651.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The frequency table shouldn't have any zero frequency entries and so such a check isn't required. Though it would be better to make sure 'state' is within limits. Signed-off-by: Viresh Kumar Tested-by: Lukasz Luba --- drivers/thermal/cpu_cooling.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index bfa9731e7cdb..9cbf7bdbeb7a 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -564,12 +564,13 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, int ret; struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; + /* Request state should be less than max_level */ + if (WARN_ON(state > cpufreq_cdev->max_level)) + return -EINVAL; + num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus); freq = cpufreq_cdev->freq_table[state].frequency; - if (!freq) - return -EINVAL; - dynamic_power = cpu_freq_to_power(cpufreq_cdev, freq) * num_cpus; ret = get_static_power(cpufreq_cdev, tz, freq, &static_power); if (ret) -- 2.12.0.432.g71c3a4f4ba37