aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2016-05-30 10:48:39 -0400
committerLinus Walleij <linus.walleij@linaro.org>2016-05-30 10:56:41 -0400
commit54d77198fdfbc4f0fe11b4252c1d9c97d51a3264 (patch)
tree0a8327b8bdf5c49781c8efad73009e4f0bb77719
parent8b92e17efe029cc19f435f9fcbdfb1e7b9beb0ef (diff)
gpio: bail out silently on NULL descriptors
In fdeb8e1547cb9dd39d5d7223b33f3565cf86c28e ("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: fdeb8e1547cb ("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>
-rw-r--r--drivers/gpio/gpiolib.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 68dbff5d8f57..246b6b051b0d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1367,10 +1367,13 @@ done:
1367/* 1367/*
1368 * This descriptor validation needs to be inserted verbatim into each 1368 * This descriptor validation needs to be inserted verbatim into each
1369 * function taking a descriptor, so we need to use a preprocessor 1369 * 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.
1371 */ 1372 */
1372#define VALIDATE_DESC(desc) do { \ 1373#define VALIDATE_DESC(desc) do { \
1373 if (!desc || !desc->gdev) { \ 1374 if (!desc) \
1375 return 0; \
1376 if (!desc->gdev) { \
1374 pr_warn("%s: invalid GPIO\n", __func__); \ 1377 pr_warn("%s: invalid GPIO\n", __func__); \
1375 return -EINVAL; \ 1378 return -EINVAL; \
1376 } \ 1379 } \
@@ -1381,7 +1384,9 @@ done:
1381 } } while (0) 1384 } } while (0)
1382 1385
1383#define VALIDATE_DESC_VOID(desc) do { \ 1386#define VALIDATE_DESC_VOID(desc) do { \
1384 if (!desc || !desc->gdev) { \ 1387 if (!desc) \
1388 return; \
1389 if (!desc->gdev) { \
1385 pr_warn("%s: invalid GPIO\n", __func__); \ 1390 pr_warn("%s: invalid GPIO\n", __func__); \
1386 return; \ 1391 return; \
1387 } \ 1392 } \