Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: return NULL from gpiod_get_optional when GPIOLIB is disabled

Given the intent behind gpiod_get_optional() and friends it does not make
sense to return -ENOSYS when GPIOLIB is disabled: the driver is expected to
work just fine without gpio so let's behave as if gpio was not found.
Otherwise we have to special-case -ENOSYS in drivers.

Note that there was objection that someone might forget to enable GPIOLIB
when dealing with a platform that has device that actually specifies
optional gpio and we'll break it. I find this unconvincing as that would
have to be the *only GPIO* in the system, which is extremely unlikely.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Dmitry Torokhov and committed by
Linus Walleij
22c40367 85c73d50

+12 -6
+6
Documentation/gpio/consumer.txt
··· 70 70 unsigned int index, 71 71 enum gpiod_flags flags) 72 72 73 + Note that gpio_get*_optional() functions (and their managed variants), unlike 74 + the rest of gpiolib API, also return NULL when gpiolib support is disabled. 75 + This is helpful to driver authors, since they do not need to special case 76 + -ENOSYS return codes. System integrators should however be careful to enable 77 + gpiolib on systems that need it. 78 + 73 79 For a function using multiple GPIOs all of those can be obtained with one call: 74 80 75 81 struct gpio_descs *gpiod_get_array(struct device *dev,
+6 -6
include/linux/gpio/consumer.h
··· 179 179 gpiod_get_optional(struct device *dev, const char *con_id, 180 180 enum gpiod_flags flags) 181 181 { 182 - return ERR_PTR(-ENOSYS); 182 + return NULL; 183 183 } 184 184 185 185 static inline struct gpio_desc *__must_check 186 186 gpiod_get_index_optional(struct device *dev, const char *con_id, 187 187 unsigned int index, enum gpiod_flags flags) 188 188 { 189 - return ERR_PTR(-ENOSYS); 189 + return NULL; 190 190 } 191 191 192 192 static inline struct gpio_descs *__must_check ··· 200 200 gpiod_get_array_optional(struct device *dev, const char *con_id, 201 201 enum gpiod_flags flags) 202 202 { 203 - return ERR_PTR(-ENOSYS); 203 + return NULL; 204 204 } 205 205 206 206 static inline void gpiod_put(struct gpio_desc *desc) ··· 240 240 devm_gpiod_get_optional(struct device *dev, const char *con_id, 241 241 enum gpiod_flags flags) 242 242 { 243 - return ERR_PTR(-ENOSYS); 243 + return NULL; 244 244 } 245 245 246 246 static inline struct gpio_desc *__must_check 247 247 devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 248 248 unsigned int index, enum gpiod_flags flags) 249 249 { 250 - return ERR_PTR(-ENOSYS); 250 + return NULL; 251 251 } 252 252 253 253 static inline struct gpio_descs *__must_check ··· 261 261 devm_gpiod_get_array_optional(struct device *dev, const char *con_id, 262 262 enum gpiod_flags flags) 263 263 { 264 - return ERR_PTR(-ENOSYS); 264 + return NULL; 265 265 } 266 266 267 267 static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)