Commit ecfb6ce5 authored by Linus Walleij's avatar Linus Walleij Committed by Greg Kroah-Hartman

gpio: bail out silently on NULL descriptors

commit 54d77198 upstream.

In fdeb8e15
("gpio: reflect base and ngpio into gpio_device")
assumed that GPIO descriptors are either valid or error
pointers, but gpiod_get_[index_]optional() actually return
NULL descriptors and then all subsequent calls should just
bail out.

Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Fixes: fdeb8e15 ("gpio: reflect base and ngpio into gpio_device")
Reported-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3a2ec155
...@@ -1339,10 +1339,13 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label) ...@@ -1339,10 +1339,13 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label)
/* /*
* This descriptor validation needs to be inserted verbatim into each * This descriptor validation needs to be inserted verbatim into each
* function taking a descriptor, so we need to use a preprocessor * function taking a descriptor, so we need to use a preprocessor
* macro to avoid endless duplication. * macro to avoid endless duplication. If the desc is NULL it is an
* optional GPIO and calls should just bail out.
*/ */
#define VALIDATE_DESC(desc) do { \ #define VALIDATE_DESC(desc) do { \
if (!desc || !desc->gdev) { \ if (!desc) \
return 0; \
if (!desc->gdev) { \
pr_warn("%s: invalid GPIO\n", __func__); \ pr_warn("%s: invalid GPIO\n", __func__); \
return -EINVAL; \ return -EINVAL; \
} \ } \
...@@ -1353,7 +1356,9 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label) ...@@ -1353,7 +1356,9 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label)
} } while (0) } } while (0)
#define VALIDATE_DESC_VOID(desc) do { \ #define VALIDATE_DESC_VOID(desc) do { \
if (!desc || !desc->gdev) { \ if (!desc) \
return; \
if (!desc->gdev) { \
pr_warn("%s: invalid GPIO\n", __func__); \ pr_warn("%s: invalid GPIO\n", __func__); \
return; \ return; \
} \ } \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment