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: 9697869 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 B0FBC603F4 for ; Tue, 25 Apr 2017 10:30:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AF4A28600 for ; Tue, 25 Apr 2017 10:30:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F9E42860C; Tue, 25 Apr 2017 10:30:06 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 69AA128600 for ; Tue, 25 Apr 2017 10:30:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1946480AbdDYK37 (ORCPT ); Tue, 25 Apr 2017 06:29:59 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:36400 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1429616AbdDYK2d (ORCPT ); Tue, 25 Apr 2017 06:28:33 -0400 Received: by mail-pf0-f180.google.com with SMTP id 194so25044951pfv.3 for ; Tue, 25 Apr 2017 03:28:23 -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=RAYLFWsucPWpEVws2SchsCEuGx0rn/o8pcsOV/0rB5Z9YKU87+c6kgux1UwoIX7jbP wN3NL5KxLcX5c9kscjRHEnBOIksGr94ohDLbP1L9sdgRQ/wMNn/pT/hAhuH4E4z54pJM VGXeiA/6RkS2cmweBrNzqa6zrbH/u8czTYFKE3ueOI6YoKKjIlLBwNG6ue7Ip/6WkqmR iZ/DeJw1gQmD+1qhMth29lZxWe51lPrmMHZJLhb0OEngYQoySKsBF/HcBGQwNcHWJ3is seWCv6iwleRawQQU6/iNpCq6o6p4oKXBxb5ygXWRpDUNnSrct1/pYvpszdPmZr9Sq69V 4tug== X-Gm-Message-State: AN3rC/5vw2Q9XqOlvqYSDH+S/KEe8dqRzTMLCu08uV+C0hXy0xISMYln VDr5glbU8zlqIXNz 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-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 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)