aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2016-06-16 05:55:55 -0400
committerLinus Walleij <linus.walleij@linaro.org>2016-06-17 12:12:19 -0400
commitbfbbe44daf64d0ccf2de123179817f3557fb9237 (patch)
tree051573607cf58ae0f743f2dc6b96ee3f308de840
parent79bb71bd1d93197ce227fa167b450b633f30a52b (diff)
gpio: make library immune to error pointers
Most functions that take a GPIO descriptor in need to check the descriptor for IS_ERR(). We do this mostly in the VALIDATE_DESC() macro except for the gpiod_to_irq() function which needs special handling. Cc: stable@vger.kernel.org Reported-by: Grygorii Strashko <grygorii.strashko@ti.com> Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com> Acked-by: Alexandre Courbot <acourbot@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--drivers/gpio/gpiolib.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index f39bf05993e7..570771ed19e6 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1373,8 +1373,12 @@ done:
1373#define VALIDATE_DESC(desc) do { \ 1373#define VALIDATE_DESC(desc) do { \
1374 if (!desc) \ 1374 if (!desc) \
1375 return 0; \ 1375 return 0; \
1376 if (IS_ERR(desc)) { \
1377 pr_warn("%s: invalid GPIO (errorpointer)\n", __func__); \
1378 return PTR_ERR(desc); \
1379 } \
1376 if (!desc->gdev) { \ 1380 if (!desc->gdev) { \
1377 pr_warn("%s: invalid GPIO\n", __func__); \ 1381 pr_warn("%s: invalid GPIO (no device)\n", __func__); \
1378 return -EINVAL; \ 1382 return -EINVAL; \
1379 } \ 1383 } \
1380 if ( !desc->gdev->chip ) { \ 1384 if ( !desc->gdev->chip ) { \
@@ -1386,8 +1390,12 @@ done:
1386#define VALIDATE_DESC_VOID(desc) do { \ 1390#define VALIDATE_DESC_VOID(desc) do { \
1387 if (!desc) \ 1391 if (!desc) \
1388 return; \ 1392 return; \
1393 if (IS_ERR(desc)) { \
1394 pr_warn("%s: invalid GPIO (errorpointer)\n", __func__); \
1395 return; \
1396 } \
1389 if (!desc->gdev) { \ 1397 if (!desc->gdev) { \
1390 pr_warn("%s: invalid GPIO\n", __func__); \ 1398 pr_warn("%s: invalid GPIO (no device)\n", __func__); \
1391 return; \ 1399 return; \
1392 } \ 1400 } \
1393 if (!desc->gdev->chip) { \ 1401 if (!desc->gdev->chip) { \
@@ -2061,7 +2069,7 @@ int gpiod_to_irq(const struct gpio_desc *desc)
2061 * requires this function to not return zero on an invalid descriptor 2069 * requires this function to not return zero on an invalid descriptor
2062 * but rather a negative error number. 2070 * but rather a negative error number.
2063 */ 2071 */
2064 if (!desc || !desc->gdev || !desc->gdev->chip) 2072 if (!desc || IS_ERR(desc) || !desc->gdev || !desc->gdev->chip)
2065 return -EINVAL; 2073 return -EINVAL;
2066 2074
2067 chip = desc->gdev->chip; 2075 chip = desc->gdev->chip;