Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10139698ybi; Wed, 24 Jul 2019 16:54:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJfTBKLEqlymNuVmwb4fuszO585ekmML77kMFs8uMZyg0vDGhTS0jYSy9lH9Mfy/TiF9FO X-Received: by 2002:a63:6a81:: with SMTP id f123mr4790185pgc.348.1564012488600; Wed, 24 Jul 2019 16:54:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564012488; cv=none; d=google.com; s=arc-20160816; b=gS6ffXjkCrwpwvtu7a/VGRGDDPQIIyQkmD16eBSoWp3WlmYTjH8u5kIzd7HoeMiRkT hud3+6jhze6o4bfAsD8Qo7qgyVdhT9Z1kQShAxHmueqlVok7ymrA9ocNcuis8Rxz5xcA rwq3w4BxWMR4DPW0jYlRjnB87Q23F1MpUK/sOFVTgTDCixZAmgVjQuI1rz5czLjNKP+y XWh4LvyBVo6i1hgJJhNkmF4Lf/rTMxRjs9HyV8LjFpGod0w+8DJEEUJbTskujsMaab9s UfarKHoSmE4Uzqbehp8O8C0w2mcld2ukq8Jk08EUO+CSXUvDwC3arUhMna3DKkLWPcnU ny+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/s82b1OgV2uWeDf5vizOd4ixcPSKEHfycrkqdB8YyaE=; b=DjkH10CfOWnKFPm0NMXPuCj3a/fKGHGkDvlaNlNIRbZwDDmGSEDskd4oi1LF2XyGwW HUHdr/CpO2feCFDy29lOW3+pVoewwzFgy2+YOQXMQELxPQPn4XrCVRJR/cxizG1W4fPz s+PO3wZu2mbjFzmixxDqqhzgQ5kCs4yZLi7zXn2apIDSootbpHsqL7+l7ZkgibOBOrEu 6PbtSc6KVU/I+pjIHQ+X2FFsLyhfaejaV6G85LDbzT1eLqTpzvVa7BV4DDy0/sMpkd2Q 2OTG6rxsWsSbnAJmSOxZE7Ksvnzg8iwAF04d1TLLWkD/ZxFa7kuI2U8o5IK9xnmnUI05 oyYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qXiEzKXR; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b36si17532111pla.289.2019.07.24.16.54.31; Wed, 24 Jul 2019 16:54:48 -0700 (PDT) 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=@kernel.org header.s=default header.b=qXiEzKXR; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388057AbfGXTbJ (ORCPT + 99 others); Wed, 24 Jul 2019 15:31:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:51734 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729137AbfGXTbH (ORCPT ); Wed, 24 Jul 2019 15:31:07 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E633A20659; Wed, 24 Jul 2019 19:31:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996666; bh=ZGjHeyQUMbx1Gh9QwJq9WrZcByKj9BknvPXN3e4fnX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qXiEzKXRhePGLIzX/DPI0Ez2P/lxpyoaebKzfvCRDlmfZeI11AytuCvGToH59FZVu XX1aSr3qq6uMmvaCb0OXufdbBjOv7W0tYVBg8QWxSA951LUEDmgcA8ACbku/2ZESkS rVgv4nv6+w1LIQgr0mTK9wFEvP4QYHxVjl7c7740= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Georg Waibel , Krzysztof Kozlowski , Linus Walleij , Mark Brown , Sasha Levin Subject: [PATCH 5.2 176/413] gpio: Fix return value mismatch of function gpiod_get_from_of_node() Date: Wed, 24 Jul 2019 21:17:47 +0200 Message-Id: <20190724191747.477033721@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 025bf37725f1929542361eef2245df30badf242e ] In case the requested gpio property is not found in the device tree, some callers of gpiod_get_from_of_node() expect a return value of NULL, others expect -ENOENT. In particular devm_fwnode_get_index_gpiod_from_child() expects -ENOENT. Currently it gets a NULL, which breaks the loop that tries all gpio_suffixes. The result is that a gpio property is not found, even though it is there. This patch changes gpiod_get_from_of_node() to return -ENOENT instead of NULL when the requested gpio property is not found in the device tree. Additionally it modifies all calling functions to properly evaluate the return value. Another approach would be to leave the return value of gpiod_get_from_of_node() as is and fix the bug in devm_fwnode_get_index_gpiod_from_child(). Other callers would still need to be reworked. The effort would be the same as with the chosen solution. Signed-off-by: Georg Waibel Reviewed-by: Krzysztof Kozlowski Reviewed-by: Linus Walleij Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/gpio/gpiolib.c | 6 +----- drivers/regulator/da9211-regulator.c | 2 ++ drivers/regulator/s2mps11.c | 4 +++- drivers/regulator/s5m8767.c | 4 +++- drivers/regulator/tps65090-regulator.c | 7 ++++--- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index e013d417a936..be1d1d2f8aaa 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -4244,8 +4244,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_index); * * Returns: * On successful request the GPIO pin is configured in accordance with - * provided @dflags. If the node does not have the requested GPIO - * property, NULL is returned. + * provided @dflags. * * In case of error an ERR_PTR() is returned. */ @@ -4267,9 +4266,6 @@ struct gpio_desc *gpiod_get_from_of_node(struct device_node *node, index, &flags); if (!desc || IS_ERR(desc)) { - /* If it is not there, just return NULL */ - if (PTR_ERR(desc) == -ENOENT) - return NULL; return desc; } diff --git a/drivers/regulator/da9211-regulator.c b/drivers/regulator/da9211-regulator.c index da37b4ccd834..0309823d2c72 100644 --- a/drivers/regulator/da9211-regulator.c +++ b/drivers/regulator/da9211-regulator.c @@ -289,6 +289,8 @@ static struct da9211_pdata *da9211_parse_regulators_dt( 0, GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE, "da9211-enable"); + if (IS_ERR(pdata->gpiod_ren[n])) + pdata->gpiod_ren[n] = NULL; n++; } diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c index 134c62db36c5..b518a81f75a3 100644 --- a/drivers/regulator/s2mps11.c +++ b/drivers/regulator/s2mps11.c @@ -821,7 +821,9 @@ static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev, 0, GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE, "s2mps11-regulator"); - if (IS_ERR(gpio[reg])) { + if (PTR_ERR(gpio[reg]) == -ENOENT) + gpio[reg] = NULL; + else if (IS_ERR(gpio[reg])) { dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n", reg, rdata[reg].name); continue; diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index bb9d1a083299..6ca27e9d5ef7 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -574,7 +574,9 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, 0, GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE, "s5m8767"); - if (IS_ERR(rdata->ext_control_gpiod)) + if (PTR_ERR(rdata->ext_control_gpiod) == -ENOENT) + rdata->ext_control_gpiod = NULL; + else if (IS_ERR(rdata->ext_control_gpiod)) return PTR_ERR(rdata->ext_control_gpiod); rdata->id = i; diff --git a/drivers/regulator/tps65090-regulator.c b/drivers/regulator/tps65090-regulator.c index ca39b3d55123..10ea4b5a0f55 100644 --- a/drivers/regulator/tps65090-regulator.c +++ b/drivers/regulator/tps65090-regulator.c @@ -371,11 +371,12 @@ static struct tps65090_platform_data *tps65090_parse_dt_reg_data( "dcdc-ext-control-gpios", 0, gflags, "tps65090"); - if (IS_ERR(rpdata->gpiod)) - return ERR_CAST(rpdata->gpiod); - if (!rpdata->gpiod) + if (PTR_ERR(rpdata->gpiod) == -ENOENT) { dev_err(&pdev->dev, "could not find DCDC external control GPIO\n"); + rpdata->gpiod = NULL; + } else if (IS_ERR(rpdata->gpiod)) + return ERR_CAST(rpdata->gpiod); } if (of_property_read_u32(tps65090_matches[idx].of_node, -- 2.20.1