From patchwork Mon Mar 13 10:07:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 95200 Delivered-To: patch@linaro.org Received: by 10.140.82.71 with SMTP id g65csp1101118qgd; Mon, 13 Mar 2017 03:09:10 -0700 (PDT) X-Received: by 10.99.238.69 with SMTP id n5mr35650709pgk.38.1489399750409; Mon, 13 Mar 2017 03:09:10 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w27si10992632pgc.348.2017.03.13.03.09.10; Mon, 13 Mar 2017 03:09:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1752142AbdCMKJI (ORCPT + 13 others); Mon, 13 Mar 2017 06:09:08 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:33942 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752202AbdCMKIf (ORCPT ); Mon, 13 Mar 2017 06:08:35 -0400 Received: by mail-pf0-f176.google.com with SMTP id v190so67570771pfb.1 for ; Mon, 13 Mar 2017 03:08:29 -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=AOIcz+wciO30oL4p0ZRIhJTdTTONLN059PT1d9X/lTs=; b=VE3tz0XLN++XDBXT6aTjZOSAdmT8Ux6LaLv20V5um4G/2Xt/b6HhVLVWnhS3WKkm64 1DSvlXbZn/xpLq0woYhH+IZ2P+a2bD7K/qYH8+siC2Q6W/wg06SXbXr3UVAtSDsN8+PO +P3nFb5V88kl1habz0jXO5J7E3AT8JCQHi48Q= 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=AOIcz+wciO30oL4p0ZRIhJTdTTONLN059PT1d9X/lTs=; b=k16uo6arWzw/l3GrPkg7as9xS2vSOzDeAYjRitgEPC98VjTnlzPQy4Gd8trGnkqTkU VNeoZLF7r1PzzmDh0ZMfB7FAAMrnU4PZptsy+2kW4td3vwlSnwsXFPatbLyZFGa50/FS um3HSzyj7gxoCjoxp8rRtkInS0TXbLQoJ/oOIowuTxNGXtltt4NO5TEC+GovCWF9tz3F ZjysmGaIWqWFWhtaJh6t7i35b6SXO4NI4N3u+xnvAoWha902IkX54ZrUS3LJf4dlbOcB 2LWXanK7r2clK5ePMHXvVF46eG9CPZ4G+lKhZXw4BuGRnhOYpIyyataSeuJGs6SsT94q k9lw== X-Gm-Message-State: AMke39lFZxp6bOrkhdP3CO87MDFyXkEEz7PK1OeasrvWxJHx8xR9UUlDqm4M+R6zihG5+J2q X-Received: by 10.98.42.151 with SMTP id q145mr36180135pfq.175.1489399707984; Mon, 13 Mar 2017 03:08:27 -0700 (PDT) Received: from localhost ([122.171.239.200]) by smtp.gmail.com with ESMTPSA id v186sm32360863pgv.44.2017.03.13.03.08.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Mar 2017 03:08:27 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , rui.zhang@intel.com, edubezval@gmail.com, Amit Daniel Kachhap , Viresh Kumar , Javi Merino Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , dan.carpenter@oracle.com Subject: [PATCH V3 5/5] thermal: cpu_cooling: Check OPP for errors Date: Mon, 13 Mar 2017 15:37:38 +0530 Message-Id: X-Mailer: git-send-email 2.7.1.410.g6faf27b 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 It is possible for dev_pm_opp_find_freq_exact() to return errors. It was all fine earlier as dev_pm_opp_get_voltage() had a check within it to check for invalid OPPs, but dev_pm_opp_put() doesn't have any similar checks and the callers need to make sure OPP is valid before calling them. Also update the later dev_warn_ratelimited() to not print the error message as the OPP is guaranteed to be valid now. Reported-by: Dan Carpenter Signed-off-by: Viresh Kumar Acked-by: Zhang Rui --- drivers/thermal/cpu_cooling.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) -- 2.7.1.410.g6faf27b diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 2f9a1c7e7b1f..c2525b585487 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -395,13 +395,20 @@ static int get_static_power(struct cpufreq_cooling_device *cpufreq_device, opp = dev_pm_opp_find_freq_exact(cpufreq_device->cpu_dev, freq_hz, true); + if (IS_ERR(opp)) { + dev_warn_ratelimited(cpufreq_device->cpu_dev, + "Failed to find OPP for frequency %lu: %ld\n", + freq_hz, PTR_ERR(opp)); + return -EINVAL; + } + voltage = dev_pm_opp_get_voltage(opp); dev_pm_opp_put(opp); if (voltage == 0) { dev_err_ratelimited(cpufreq_device->cpu_dev, - "Failed to get voltage for frequency %lu: %ld\n", - freq_hz, IS_ERR(opp) ? PTR_ERR(opp) : 0); + "Failed to get voltage for frequency %lu\n", + freq_hz); return -EINVAL; }