From patchwork Mon Feb 6 10:26:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 93395 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1644089qgi; Mon, 6 Feb 2017 02:27:05 -0800 (PST) X-Received: by 10.84.217.133 with SMTP id p5mr16467269pli.164.1486376825856; Mon, 06 Feb 2017 02:27:05 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33si300718plq.10.2017.02.06.02.27.05; Mon, 06 Feb 2017 02:27:05 -0800 (PST) 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 S1751640AbdBFK0x (ORCPT + 25 others); Mon, 6 Feb 2017 05:26:53 -0500 Received: from mail-pg0-f42.google.com ([74.125.83.42]:33093 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751580AbdBFK0t (ORCPT ); Mon, 6 Feb 2017 05:26:49 -0500 Received: by mail-pg0-f42.google.com with SMTP id 204so27635404pge.0 for ; Mon, 06 Feb 2017 02:26:49 -0800 (PST) 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=+7329xPLZdJjz5qST2xIGSfyped1oov5u527k6wgiOo=; b=Je3TC78GIfWCFfcPO+wzI2WLwgMcBiaPC6Ix5h/Q23ISLxG+ko9wg6XUbJc1bdiBkH DaHLOQ2LSPPhEG1582UsEVsN8FHaEaozqeZTYx9iXNvwDP3BiRaJMbxiSEf14tLnDmI5 RXd1Xl9sm0F3i80kZFIaUz7WYImJr66/k9N3k= 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=+7329xPLZdJjz5qST2xIGSfyped1oov5u527k6wgiOo=; b=gLGFCKJLC/jpcr627FEBhD3fFCrbgic/4nRG8BgKlemz9khS718uJcGNkd2jhe+xBC qTh4XSRhj3RsdM5WJ3+bRwEU/OMM40KBWIFscQciOiwlDW7w+3t7EsnqKMBjB4AQw5NK nf7cz0Tft4O78LxtCUivmhLqXIoY256Dnhy7luKc7rj30oiONx8gMzsgXg7IiswClNIJ AiK10SnokVtCir8Xh7Txjg18cM/Y0I5ypD6fHv/vF5RlYMNn+NJK9nfSAjWM6fIsIR7O SyBH9YFMU8UWlO07IDpfIMA+Aolo5QUZMwLTMwJei3Z6XUiwLTWNzioC5y6vPqkI5A9M z5sQ== X-Gm-Message-State: AIkVDXKlNTlO5xGYcbqehalqnKd+B0edpi63XtiyQHFmBLGZRPTd20D7huEp1Qvk3LJxamZp X-Received: by 10.84.176.131 with SMTP id v3mr16552638plb.20.1486376808845; Mon, 06 Feb 2017 02:26:48 -0800 (PST) Received: from localhost ([122.172.165.189]) by smtp.gmail.com with ESMTPSA id 19sm1265096pft.46.2017.02.06.02.26.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Feb 2017 02:26:48 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Amit Daniel Kachhap , Viresh Kumar , Javi Merino , Zhang Rui , Eduardo Valentin Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Dan Carpenter Subject: [PATCH 2/3] thermal: cpu_cooling: Check OPP for errors Date: Mon, 6 Feb 2017 15:56:28 +0530 Message-Id: X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: <232171cd9d89c2179e10e1f2aed71ad7fc1f7872.1486376756.git.viresh.kumar@linaro.org> References: <232171cd9d89c2179e10e1f2aed71ad7fc1f7872.1486376756.git.viresh.kumar@linaro.org> In-Reply-To: <232171cd9d89c2179e10e1f2aed71ad7fc1f7872.1486376756.git.viresh.kumar@linaro.org> References: <232171cd9d89c2179e10e1f2aed71ad7fc1f7872.1486376756.git.viresh.kumar@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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 85fdbf762fa0..9534540434e2 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -431,13 +431,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_warn_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; }