From patchwork Wed Apr 19 05:29:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 9686867 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2991960375 for ; Wed, 19 Apr 2017 05:32:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D3DC26490 for ; Wed, 19 Apr 2017 05:32:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10CB32815E; Wed, 19 Apr 2017 05:32:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A208926490 for ; Wed, 19 Apr 2017 05:32:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760044AbdDSFcJ (ORCPT ); Wed, 19 Apr 2017 01:32:09 -0400 Received: from mail-pg0-f52.google.com ([74.125.83.52]:36798 "EHLO mail-pg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759999AbdDSFbe (ORCPT ); Wed, 19 Apr 2017 01:31:34 -0400 Received: by mail-pg0-f52.google.com with SMTP id g2so7364887pge.3 for ; Tue, 18 Apr 2017 22:31:34 -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=+uptI25DhQOS9ZVHX6zgqKgGv81u8Oej0uJ+6fqJ6Xw=; b=OVTHPRhtJNkAyhOt/4eQDWyu2DmvzIAPJPaGo1yuyKl+0olAX3L7DPlWP0Ah7LU5qq Uu313LEuzrr5o9lxJp9ck/UjmXrv2qiOPyS0Ii7BrtJxx2P4fy/91mk75gKw6oUX5dKl 5eBql7H/L2RYtIV6Uo+RlQKh3bGs4NxoKhfI8= 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=+uptI25DhQOS9ZVHX6zgqKgGv81u8Oej0uJ+6fqJ6Xw=; b=c+OSsA/qeC94HSr25DhQuJNyE/KyvagtNAx8ZQ0P3nWRa9JlVGnXcC5zXfF5RYpPDT RyNvHYP61lg1sUeH7utsUybwS6ubU4eG+o5Au/ZZRTmqpyZR8e+UWyXw6TNr9mlvpUlu SQtZBjy5LNzeTop6+nvyNPh2L4BVwuEMJJMz03seyu1cuEvXo0BfKXBXZt89GKUqVhHs rZtCIYwCBLRONhHfkQUSV1o6cU/4A1FStYWZ+zPVlmCxiYAZg2jU1oTICcsAAwSsuyJ4 OgzimT6J/FIOMY/8M+vA4lCRMFK+keNo6HCWGVHzvnGEAs8rFL9OiRdYiJLdNny6cFbm W1Fw== X-Gm-Message-State: AN3rC/52Y1J2U6QKqLrLVYyiVeA9ATjLHJ6p12Jf+tRjEO+fnQa1iEIb sslGC/dYGeYVSBJw X-Received: by 10.84.129.131 with SMTP id b3mr1588839plb.1.1492579893626; Tue, 18 Apr 2017 22:31:33 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id t141sm1682082pgb.3.2017.04.18.22.31.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:31:32 -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 V3 16/17] thermal: cpu_cooling: 'freq' can't be zero in cpufreq_state2power() Date: Wed, 19 Apr 2017 10:59:11 +0530 Message-Id: <17b27faf383d82aa7a5a6330f08c185663aac447.1492579345.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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 c85b217d16c8..dc73405b04f2 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -560,12 +560,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)