Commit c0a1ecb9 authored by Linus Walleij's avatar Linus Walleij Committed by Richard Weinberger

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: default avatarGrygorii Strashko <grygorii.strashko@ti.com>
Reviewed-by: default avatarGrygorii Strashko <grygorii.strashko@ti.com>
Acked-by: default avatarAlexandre Courbot <acourbot@nvidia.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 39243ee7
...@@ -1373,8 +1373,12 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label) ...@@ -1373,8 +1373,12 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label)
#define VALIDATE_DESC(desc) do { \ #define VALIDATE_DESC(desc) do { \
if (!desc) \ if (!desc) \
return 0; \ return 0; \
if (IS_ERR(desc)) { \
pr_warn("%s: invalid GPIO (errorpointer)\n", __func__); \
return PTR_ERR(desc); \
} \
if (!desc->gdev) { \ if (!desc->gdev) { \
pr_warn("%s: invalid GPIO\n", __func__); \ pr_warn("%s: invalid GPIO (no device)\n", __func__); \
return -EINVAL; \ return -EINVAL; \
} \ } \
if ( !desc->gdev->chip ) { \ if ( !desc->gdev->chip ) { \
...@@ -1386,8 +1390,12 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label) ...@@ -1386,8 +1390,12 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label)
#define VALIDATE_DESC_VOID(desc) do { \ #define VALIDATE_DESC_VOID(desc) do { \
if (!desc) \ if (!desc) \
return; \ return; \
if (IS_ERR(desc)) { \
pr_warn("%s: invalid GPIO (errorpointer)\n", __func__); \
return; \
} \
if (!desc->gdev) { \ if (!desc->gdev) { \
pr_warn("%s: invalid GPIO\n", __func__); \ pr_warn("%s: invalid GPIO (no device)\n", __func__); \
return; \ return; \
} \ } \
if (!desc->gdev->chip) { \ if (!desc->gdev->chip) { \
...@@ -2061,7 +2069,7 @@ int gpiod_to_irq(const struct gpio_desc *desc) ...@@ -2061,7 +2069,7 @@ int gpiod_to_irq(const struct gpio_desc *desc)
* requires this function to not return zero on an invalid descriptor * requires this function to not return zero on an invalid descriptor
* but rather a negative error number. * but rather a negative error number.
*/ */
if (!desc || !desc->gdev || !desc->gdev->chip) if (!desc || IS_ERR(desc) || !desc->gdev || !desc->gdev->chip)
return -EINVAL; return -EINVAL;
chip = desc->gdev->chip; chip = desc->gdev->chip;
......
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