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: 97602 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159549qgf; Tue, 18 Apr 2017 22:32:23 -0700 (PDT) X-Received: by 10.98.81.132 with SMTP id f126mr1187707pfb.95.1492579943509; Tue, 18 Apr 2017 22:32:23 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k4si1305947pgn.218.2017.04.18.22.32.23; Tue, 18 Apr 2017 22:32:23 -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 S1760056AbdDSFcM (ORCPT + 17 others); Wed, 19 Apr 2017 01:32:12 -0400 Received: from mail-pg0-f52.google.com ([74.125.83.52]:35615 "EHLO mail-pg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759992AbdDSFbe (ORCPT ); Wed, 19 Apr 2017 01:31:34 -0400 Received: by mail-pg0-f52.google.com with SMTP id 72so7373863pge.2 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=kyarAXGnhV77fEeYJyEswDZrph4rl4LQDxUjK0ye+MgJfpSmYrKJENjDhDKIfJuw49 MVbwImSS4WQrTiAx2JSRJB0OsdSxk47zqUX/C9pch+e7bPCUUPNTv6+U3PVyFJbv18GT gjuGULXj/rNvA4d8hNl2M74XxYBy/v8oHTjAIGnXv5jk6N5ytv2X0rV7U4igJNPOxb9u C4HURwaYHMoMqvfX3Qn2tRJYeCcuNGoCWstDyu9GLHyOhaQIw9nQ/Vy6rJPsgAuRYGHy /VQIEwSKYkmBpsLe87J/mjdhDkax8KQ2q7kcIJCJWiYWOw+27vnfkiAUpi2Gw1uMlqLo MKSg== X-Gm-Message-State: AN3rC/7cnVmQoY4OeZ8pQKZz4IDpjF7EwesxL9Fmr8raymj0p7hPQhwu 8oMl6Aw6j8RWzyN1 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-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 --- 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 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)