From patchwork Mon Feb 15 16:26:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 61941 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1163630lbl; Mon, 15 Feb 2016 08:27:06 -0800 (PST) X-Received: by 10.66.234.166 with SMTP id uf6mr24816152pac.122.1455553626350; Mon, 15 Feb 2016 08: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 f5si44246307pat.113.2016.02.15.08.27.06; Mon, 15 Feb 2016 08:27:06 -0800 (PST) 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; 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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751227AbcBOQ1F (ORCPT + 11 others); Mon, 15 Feb 2016 11:27:05 -0500 Received: from mail-pa0-f43.google.com ([209.85.220.43]:36148 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751137AbcBOQ1E (ORCPT ); Mon, 15 Feb 2016 11:27:04 -0500 Received: by mail-pa0-f43.google.com with SMTP id yy13so87908701pab.3 for ; Mon, 15 Feb 2016 08:27:03 -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; bh=YxL2Kte0ZlDuyoJ+y3/Fk8uxkT8Ta7FohstdA3K1uoo=; b=Hp0FD4bunFAJBApBNBwHprnfjNDdNnC0QxVjUZ1JOLClXmHramKllwQBZ7sC2/hV4v pSxzxjyj2g7lMAOOEGunQODs0fq+jiL+s9M/N/LLzXvkd2oNelNv6XM53UWv2JT3PUpT Bn+acqMimBry1toJSwBKjsKBh/6DY+BfUvPEY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YxL2Kte0ZlDuyoJ+y3/Fk8uxkT8Ta7FohstdA3K1uoo=; b=UOH9ZTDklh8qonxzne45kr9pLLZkTXGhak8pIzBIuzI3vdS5ugRmu7TdJu/uuLl0SJ P+Vtd8dvmllqjWkhyA0yKdO9bCh49DE8ygYNbxTi2osnuZW64jQB28VzSi8sWcYQSeu8 gUZrotylwfdC4GJMagVoN3VouxDCnQLSpaDxzipDjXqo43bBD/D7TjUPpNrsk4Z5YQD8 jGRuAcolNQJvvL0jHR+Ah+4O3yFeGAQW2G6bzR1Ve7eBgaSVFk4mW93iVLIQACtVXXSQ 50JWjVl+ZHv2PL7wLolOilb+KqFC1Zz28DoWB6UpPp4MldR2MfzHX9pqSLXH/9WhX4cK ZUqQ== X-Gm-Message-State: AG10YOQkDVR7wbwDdZpTTnTKBVMeJHx+k8VIVRtTyeN9M7KmD8BEucI0sHwJdQS3pbYK3hpj X-Received: by 10.66.155.232 with SMTP id vz8mr24493912pab.53.1455553622987; Mon, 15 Feb 2016 08:27:02 -0800 (PST) Received: from localhost ([122.172.89.184]) by smtp.gmail.com with ESMTPSA id 19sm39617649pfb.64.2016.02.15.08.27.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Feb 2016 08:27:02 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Viresh Kumar , Jon Hunter , linux-kernel@vger.kernel.org Subject: [PATCH] PM / OPP: Initialize regulator pointer to an error value Date: Mon, 15 Feb 2016 21:56:42 +0530 Message-Id: <743509d913cbc0e725bea52281be03b009e02bb5.1455553501.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: <1455544758-7718-1-git-send-email-jonathanh@nvidia.com> References: <1455544758-7718-1-git-send-email-jonathanh@nvidia.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org We are currently required to do two checks for regulator pointer: IS_ERR() and IS_NULL(). And multiple instances are reported, about both of these not being used consistently and so resulting in crashes. Fix that by initializing regulator pointer with an error value and checking it only against an error. This makes code consistent and efficient. Reported-by: Jon Hunter Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) -- 2.7.1.410.g6faf27b -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index d7cd4e265766..146b6197d598 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -257,7 +257,7 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev) } reg = dev_opp->regulator; - if (IS_ERR_OR_NULL(reg)) { + if (IS_ERR(reg)) { /* Regulator may not be required for device */ if (reg) dev_err(dev, "%s: Invalid regulator (%ld)\n", __func__, @@ -798,6 +798,9 @@ static struct device_opp *_add_device_opp(struct device *dev) of_node_put(np); } + /* Set regulator to a non-NULL error value */ + dev_opp->regulator = ERR_PTR(-EFAULT); + /* Find clk for the device */ dev_opp->clk = clk_get(dev, NULL); if (IS_ERR(dev_opp->clk)) { @@ -845,7 +848,7 @@ static void _remove_device_opp(struct device_opp *dev_opp) if (dev_opp->prop_name) return; - if (!IS_ERR_OR_NULL(dev_opp->regulator)) + if (!IS_ERR(dev_opp->regulator)) return; /* Release clk */ @@ -975,7 +978,7 @@ static bool _opp_supported_by_regulators(struct dev_pm_opp *opp, { struct regulator *reg = dev_opp->regulator; - if (!IS_ERR_OR_NULL(reg) && + if (!IS_ERR(reg) && !regulator_is_supported_voltage(reg, opp->u_volt_min, opp->u_volt_max)) { pr_warn("%s: OPP minuV: %lu maxuV: %lu, not supported by regulator\n", @@ -1435,7 +1438,7 @@ int dev_pm_opp_set_regulator(struct device *dev, const char *name) } /* Already have a regulator set */ - if (WARN_ON(!IS_ERR_OR_NULL(dev_opp->regulator))) { + if (WARN_ON(!IS_ERR(dev_opp->regulator))) { ret = -EBUSY; goto err; } @@ -1486,7 +1489,7 @@ void dev_pm_opp_put_regulator(struct device *dev) goto unlock; } - if (IS_ERR_OR_NULL(dev_opp->regulator)) { + if (IS_ERR(dev_opp->regulator)) { dev_err(dev, "%s: Doesn't have regulator set\n", __func__); goto unlock; } @@ -1495,7 +1498,7 @@ void dev_pm_opp_put_regulator(struct device *dev) WARN_ON(!list_empty(&dev_opp->opp_list)); regulator_put(dev_opp->regulator); - dev_opp->regulator = ERR_PTR(-EINVAL); + dev_opp->regulator = ERR_PTR(-EFAULT); /* Try freeing device_opp if this was the last blocking resource */ _remove_device_opp(dev_opp);