Skip to content

Commit

Permalink
gpio: bail out silently on NULL descriptors
Browse files Browse the repository at this point in the history
In fdeb8e1
("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: stable@vger.kernel.org
Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Fixes: fdeb8e1 ("gpio: reflect base and ngpio into gpio_device")
Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Linus Walleij committed May 30, 2016
1 parent 8b92e17 commit 54d7719
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1367,10 +1367,13 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label)
/*
* This descriptor validation needs to be inserted verbatim into each
* 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 { \
if (!desc || !desc->gdev) { \
if (!desc) \
return 0; \
if (!desc->gdev) { \
pr_warn("%s: invalid GPIO\n", __func__); \
return -EINVAL; \
} \
Expand All @@ -1381,7 +1384,9 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label)
} } while (0)

#define VALIDATE_DESC_VOID(desc) do { \
if (!desc || !desc->gdev) { \
if (!desc) \
return; \
if (!desc->gdev) { \
pr_warn("%s: invalid GPIO\n", __func__); \
return; \
} \
Expand Down

0 comments on commit 54d7719

Please sign in to comment.