linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RFC: let gpiod_get_optional et all return NULL when GPIOLIB is not enabled
@ 2015-02-12  9:03 Uwe Kleine-König
  2015-03-06  8:26 ` Linus Walleij
  0 siblings, 1 reply; 10+ messages in thread
From: Uwe Kleine-König @ 2015-02-12  9:03 UTC (permalink / raw)
  To: Alexandre Courbot, Linus Walleij; +Cc: kernel, linux-arm-kernel, linux-gpio

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)
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-04-28  6:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-12  9:03 [PATCH] RFC: let gpiod_get_optional et all return NULL when GPIOLIB is not enabled Uwe Kleine-König
2015-03-06  8:26 ` Linus Walleij
2015-03-06  8:59   ` Uwe Kleine-König
     [not found]     ` <20150306085957.GC10717-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2015-03-09 16:44       ` Linus Walleij
2015-04-09  2:20         ` Alexandre Courbot
2015-04-27 13:05           ` Linus Walleij
2015-04-27 15:21           ` Uwe Kleine-König
2015-04-28  3:31             ` Alexandre Courbot
     [not found]               ` <CAAVeFuKMiHhT8o1PCETNTys8EATcVdy7xfy+P+o_2r6BwAXEgw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-04-28  6:45                 ` Uwe Kleine-König
2015-04-28  6:46                   ` Alexandre Courbot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).