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; } From patchwork Mon Feb 6 10:26:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 93396 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1644091qgi; Mon, 6 Feb 2017 02:27:06 -0800 (PST) X-Received: by 10.99.36.7 with SMTP id k7mr12483381pgk.201.1486376826320; Mon, 06 Feb 2017 02:27:06 -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:06 -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 S1751715AbdBFK07 (ORCPT + 25 others); Mon, 6 Feb 2017 05:26:59 -0500 Received: from mail-pf0-f180.google.com ([209.85.192.180]:36655 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751574AbdBFK0w (ORCPT ); Mon, 6 Feb 2017 05:26:52 -0500 Received: by mail-pf0-f180.google.com with SMTP id 189so23250022pfu.3 for ; Mon, 06 Feb 2017 02:26:52 -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=ivgz9RHZCreyGp7b5fLMZTQx71Ow0nf7fPFdmtccQPM=; b=ab7DF1jo+OJuMg595X6nJEnXhBB7wKlbgzcvRtJIAgbL00IZN0XAN3ddiLf8Pk6ouv MB6Xlw/61fxLg9ICkTNtszVUia7UuHCJhXbhNBd3nmSOqwG4Jggz4+XStvt3B8B/hCWc nNa1bScO+mNf6ZZYQwy0eqYATHdpjT/YoVoHo= 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=ivgz9RHZCreyGp7b5fLMZTQx71Ow0nf7fPFdmtccQPM=; b=Wh9ePKUsJ3E/uEGJk68CRUPv+0IbHzrTHXM4WR/J1GMFxhhZDIOtRfjcsUolPbkwFa nDYiJL+Yh7s34pOiSiIOrT+Ldn+PKRjAH29A+4z61L6PPl9JsO6mbK/vEPRyHG/2fd6P zCp+yUZS5+bSWOd+t/SPm+wewYtjkQ2wBJ0SwZPaqnzwX5T1cGTHty5CRc9YWiAQBlB6 JSqeaBEh0mEuEALlvdiAw5xZ6H3HFu3mKNrb9JOjLUTr5XYbf75JEdBJrM9f2K7jod8p 2kv/Bw+dtxuVpFrbOQT6uoERO0l+K7Aynb280Z/Gfds8y3Vm8w2SzEEiK8eVCHTolvAY vAzA== X-Gm-Message-State: AIkVDXLAAburRtPJG1iEIDQ5uo4ggLtcVOCFo4fO39HDFedW7hStQUcWIrWn1wMP9rrmY6CM X-Received: by 10.84.197.1 with SMTP id m1mr16495267pld.123.1486376812022; Mon, 06 Feb 2017 02:26:52 -0800 (PST) Received: from localhost ([122.172.165.189]) by smtp.gmail.com with ESMTPSA id b75sm1160751pfb.90.2017.02.06.02.26.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Feb 2017 02:26:51 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Zhang Rui , Eduardo Valentin Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Viresh Kumar , Dan Carpenter Subject: [PATCH 3/3] thermal: devfreq: Check OPP for errors Date: Mon, 6 Feb 2017 15:56:29 +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/devfreq_cooling.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) -- 2.7.1.410.g6faf27b diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c index cf71550b9d00..ee013fc02980 100644 --- a/drivers/thermal/devfreq_cooling.c +++ b/drivers/thermal/devfreq_cooling.c @@ -225,13 +225,20 @@ get_static_power(struct devfreq_cooling_device *dfc, unsigned long freq) if (PTR_ERR(opp) == -ERANGE) opp = dev_pm_opp_find_freq_exact(dev, freq, false); + if (IS_ERR(opp)) { + dev_warn_ratelimited(dev, + "Failed to find OPP for frequency %lu: %ld\n", + freq, PTR_ERR(opp)); + return 0; + } + voltage = dev_pm_opp_get_voltage(opp) / 1000; /* mV */ dev_pm_opp_put(opp); if (voltage == 0) { dev_warn_ratelimited(dev, - "Failed to get voltage for frequency %lu: %ld\n", - freq, IS_ERR(opp) ? PTR_ERR(opp) : 0); + "Failed to get voltage for frequency %lu\n", + freq); return 0; }