From patchwork Fri Jul 1 15:40:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 643089 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3rh0xN13f8z9sR8 for ; Sat, 2 Jul 2016 01:40:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752199AbcGAPkW (ORCPT ); Fri, 1 Jul 2016 11:40:22 -0400 Received: from www381.your-server.de ([78.46.137.84]:59933 "EHLO www381.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751218AbcGAPkU (ORCPT ); Fri, 1 Jul 2016 11:40:20 -0400 Received: from [88.198.220.131] (helo=sslproxy02.your-server.de) by www381.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1bJ0YD-0004HN-9H; Fri, 01 Jul 2016 17:40:17 +0200 Received: from [2003:86:2c09:5900:8200:bff:fe9b:6612] (helo=lars-laptop.ad.analog.com) by sslproxy02.your-server.de with esmtpsa (TLSv1.2:AES256-SHA:256) (Exim 4.84_2) (envelope-from ) id 1bJ0YD-00087A-2F; Fri, 01 Jul 2016 17:40:17 +0200 From: Lars-Peter Clausen To: Linus Walleij , Alexandre Courbot Cc: linux-gpio@vger.kernel.org, Lars-Peter Clausen Subject: [PATCH] gpiolib: of_find_gpio(): Don't discard errors Date: Fri, 1 Jul 2016 17:40:09 +0200 Message-Id: <1467387609-13811-1-git-send-email-lars@metafoo.de> X-Mailer: git-send-email 2.1.4 X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.99.2/21824/Fri Jul 1 16:28:01 2016) Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Since commit dd34c37aa3e8 ("gpio: of: Allow -gpio suffix for property names") when requesting a GPIO from the devicetree gpiolib looks for properties with both the '-gpio' and the '-gpios' suffix. This was implemented by first searching for the property with the '-gpios' suffix and if that yields an error try the '-gpio' suffix. This approach has the issue that any error returned when looking for the '-gpios' suffix is silently discarded. Commit 06fc3b70f1dc ("gpio: of: Fix handling for deferred probe for -gpio suffix") partially addressed the issue by treating the EPROBE_DEFER error as a special condition. This fixed the case when the property is specified, but the GPIO provider is not ready yet. But there are other cases in which of_get_named_gpiod_flags() returns an error even though the property is specified, e.g. if the specification is incorrect. of_find_gpio() should only try to look for the property with the '-gpio' suffix if no property with the '-gpios' suffix was found. If the property was not found of_get_named_gpiod_flags() will return -ENOENT, so update the condition to abort and propagate the error to the caller in all other cases. This is important for gpiod_get_optinal() and friends to behave correctly in case the specifier contains errors. Without this patch they'll return NULL if the property uses the '-gpios' suffix and the specifier contains errors, which falsely indicates to the caller that no GPIO was specified. Signed-off-by: Lars-Peter Clausen --- drivers/gpio/gpiolib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6566b93..8f1d51b 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2838,7 +2838,7 @@ static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx, &of_flags); - if (!IS_ERR(desc) || (PTR_ERR(desc) == -EPROBE_DEFER)) + if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) break; }