From patchwork Mon Apr 17 06:02:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97506 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1212781qgf; Sun, 16 Apr 2017 23:04:00 -0700 (PDT) X-Received: by 10.84.217.148 with SMTP id p20mr13466363pli.164.1492409040288; Sun, 16 Apr 2017 23:04:00 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b27si1949596pgn.296.2017.04.16.23.04.00; Sun, 16 Apr 2017 23:04: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 sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933048AbdDQGD5 (ORCPT + 14 others); Mon, 17 Apr 2017 02:03:57 -0400 Received: from mail-pf0-f178.google.com ([209.85.192.178]:36521 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933013AbdDQGDs (ORCPT ); Mon, 17 Apr 2017 02:03:48 -0400 Received: by mail-pf0-f178.google.com with SMTP id 194so22274895pfv.3 for ; Sun, 16 Apr 2017 23:03:38 -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=wlj9j5ihMgaH4EXXSc6HhYi+C7isirulW9ZknZc3wDo=; b=jNo57gXU9Zae8BSPWKcDFt6eNVI3WUz+qewTwdAnumzJHJqKODnM/YvmmypsXVoZ79 5NA5z2IefGVJcPJWehJj90AHgrdN17u3jeWzum6veHo1/btQH98I2e6Pni1D+zcMOFJA KE3Jc68pPRmh0npYIstQ6h7q12N8JzNyGgVf0= 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=wlj9j5ihMgaH4EXXSc6HhYi+C7isirulW9ZknZc3wDo=; b=bln5LgCZ9wKh57WE79tq1flf9Ah5FENqUatZ2b3pCCcjPgSWYiR7VJEe19+ZK3JQib ylI2bbIxRJLDB3G2F4z0KUqS99H+Lsfou1tlZ7vPv5G/1YW7WmiR2v+GSnw2iU4qdv/M yWIhzMZLSNHS4XJETcq0CYlBbyWnjGY9XnROxoxtKC+af0RUXXmbBChzLddEQOqvvpNL VmQQJs2fMgBW4zV2elnxVtAOzHvmT22Z1Nuc46+XsfDEmeIgWMzqNXqwAYHnn6iuFfai SUhq9BXLDAV92iJPNGJE1BzUXgXSNM5Kj2+ZOVibeie069iAzqQCzIh+4pGIpPktdsDd Brgw== X-Gm-Message-State: AN3rC/4oYRAlHw9onrDroXC1117SR7xlKLUa7MOnfvQQdCw8Vw2MdzHQ UPIMm0j38LYYWZlA X-Received: by 10.98.71.201 with SMTP id p70mr9894959pfi.102.1492409017950; Sun, 16 Apr 2017 23:03:37 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id q1sm4768263pfl.89.2017.04.16.23.03.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Apr 2017 23:03:37 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , 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 Subject: [PATCH V2 16/17] thermal: cpu_cooling: 'freq' can't be zero in cpufreq_state2power() Date: Mon, 17 Apr 2017 11:32:01 +0530 Message-Id: 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 1e4c5d13afbf..dfc3638ea939 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)