From patchwork Tue Apr 25 10:27:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 98192 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1880206qgf; Tue, 25 Apr 2017 03:29:59 -0700 (PDT) X-Received: by 10.99.145.200 with SMTP id l191mr28046620pge.123.1493116199170; Tue, 25 Apr 2017 03:29:59 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h15si21874159plk.313.2017.04.25.03.29.58; Tue, 25 Apr 2017 03:29:59 -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 sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1946477AbdDYK3q (ORCPT + 10 others); 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 Received: by mail-pf0-f170.google.com with SMTP id v14so21414448pfd.2 for ; Tue, 25 Apr 2017 03:28:42 -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:in-reply-to:references :in-reply-to:references; bh=JfbMSbicd9dGkyTY35BPm2YPIqRBgsjujao2cuz+Dbs=; b=YRwNmcagKWHP1Dx3eSKFoIbzViyM7Pp4uv5e9u5Y7/X/NycU8+FAaPb3Ox/9OsVQWa M/AWG7Cd1BjEd6am6NR6b/0Z0ykgVFX7a/qJB6SRpI33K2ICOMLRdbozCAf28y2Q1I8H EAdN1D7neEUo+HDZArykydSOnwzYsWnwrYe7g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=JfbMSbicd9dGkyTY35BPm2YPIqRBgsjujao2cuz+Dbs=; b=Bfv4QP3VJKgRekXRJ2qs9MkDNKqOvNqvlTgnGFsnu2dVA0pd+u/8POTglP5D59S2Rl tGWlBDUmY2buRmvjxZMtvKIU/VHrv/VrVy2l5QzIcZexB1D8otkyfH1mwPnfdyNIP61Z TkBk+S6qvx/Y+6H8urgAo+I7h2Og1wI1moKW7YniSXvzIfPAFJ1RGpnHltvVauw7WxCh e+evipRbnRKgSSBuPsHmUKxXjO4b+h3nRqc5vMoVSnOcfH6J2UF4VzaQFCTYk8fY3byB C91CB0A+PDMJmGye8xr3Gwd1yOSWWzDUqj2DzVisUIuFNNzuelyiliKI+s2gZFuXbH4U IVOw== X-Gm-Message-State: AN3rC/5gBlSrGG1KYCWpiNwTC+EgSsG4asu6shYKC3rinQEo6sD9dnF1 gGTs0ZCG3qxIhCUL X-Received: by 10.99.6.14 with SMTP id 14mr27548224pgg.83.1493116102805; Tue, 25 Apr 2017 03:28:22 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id e13sm35763300pfb.30.2017.04.25.03.28.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 03:28:22 -0700 (PDT) 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 Precedence: bulk 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(-) -- 2.12.0.432.g71c3a4f4ba37 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)