From patchwork Thu Feb 12 09:03:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 439135 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 C382A1400A0 for ; Thu, 12 Feb 2015 20:03:48 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755147AbbBLJDm (ORCPT ); Thu, 12 Feb 2015 04:03:42 -0500 Received: from metis.ext.pengutronix.de ([92.198.50.35]:40658 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755096AbbBLJDi (ORCPT ); Thu, 12 Feb 2015 04:03:38 -0500 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1YLpgM-0002Nf-Op; Thu, 12 Feb 2015 10:03:34 +0100 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.84) (envelope-from ) id 1YLpgL-0001GW-Tz; Thu, 12 Feb 2015 10:03:33 +0100 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Alexandre Courbot , Linus Walleij Cc: kernel@pengutronix.de, linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org Subject: [PATCH] RFC: let gpiod_get_optional et all return NULL when GPIOLIB is not enabled Date: Thu, 12 Feb 2015 10:03:29 +0100 Message-Id: <1423731809-4800-1-git-send-email-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.1.4 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-gpio@vger.kernel.org Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org If you look for example at sound/soc/codecs/adau1977.c it has: adau1977->reset_gpio = devm_gpiod_get(dev, "reset"); if (IS_ERR(adau1977->reset_gpio)) { ret = PTR_ERR(adau1977->reset_gpio); if (ret != -ENOENT && ret != -ENOSYS) return PTR_ERR(adau1977->reset_gpio); adau1977->reset_gpio = NULL; } This code could better make use of devm_gpiod_get_optional like: adau1977->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); if (IS_ERR(adau1977->reset_gpio)) return PTR_ERR(adau1977->reset_gpio); but this slightly changes semantics. I.e. if GPIOLIB is not enabled devm_gpiod_get_optional unconditionally returns -ENOSYS which is ignored explicitly above but an error in the changed code. I wonder if gpiod_get_optional et all should be changed to return NULL instead. The obvious downside is that if the device tree specifies a reset-gpio and the kernel just fails to use it because there is some code missing, this should better be an error. (The adau1977 code has this problem already know, but when changing devm_gpiod_get_optional all callers are affected.) What do you think? --- include/linux/gpio/consumer.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index fd85cb120ee0..f68244ffd3a9 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -132,14 +132,14 @@ static inline struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev, const char *con_id, enum gpiod_flags flags) { - return ERR_PTR(-ENOSYS); + return NULL; } static inline struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, const char *con_id, unsigned int index, enum gpiod_flags flags) { - return ERR_PTR(-ENOSYS); + return NULL; } static inline void gpiod_put(struct gpio_desc *desc) @@ -171,14 +171,14 @@ static inline struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev, const char *con_id, enum gpiod_flags flags) { - return ERR_PTR(-ENOSYS); + return NULL; } static inline struct gpio_desc *__must_check __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, unsigned int index, enum gpiod_flags flags) { - return ERR_PTR(-ENOSYS); + return NULL; } static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)