Skip to content

Commit 54d7719

Browse files
committed
gpio: bail out silently on NULL descriptors
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>
1 parent 8b92e17 commit 54d7719

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/gpio/gpiolib.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,10 +1367,13 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label)
13671367
/*
13681368
* This descriptor validation needs to be inserted verbatim into each
13691369
* function taking a descriptor, so we need to use a preprocessor
1370-
* macro to avoid endless duplication.
1370+
* macro to avoid endless duplication. If the desc is NULL it is an
1371+
* optional GPIO and calls should just bail out.
13711372
*/
13721373
#define VALIDATE_DESC(desc) do { \
1373-
if (!desc || !desc->gdev) { \
1374+
if (!desc) \
1375+
return 0; \
1376+
if (!desc->gdev) { \
13741377
pr_warn("%s: invalid GPIO\n", __func__); \
13751378
return -EINVAL; \
13761379
} \
@@ -1381,7 +1384,9 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label)
13811384
} } while (0)
13821385

13831386
#define VALIDATE_DESC_VOID(desc) do { \
1384-
if (!desc || !desc->gdev) { \
1387+
if (!desc) \
1388+
return; \
1389+
if (!desc->gdev) { \
13851390
pr_warn("%s: invalid GPIO\n", __func__); \
13861391
return; \
13871392
} \

0 commit comments

Comments
 (0)