Skip to content

Commit

Permalink
gpio: make library immune to error pointers
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Walleij committed Jun 17, 2016
1 parent 79bb71b commit bfbbe44
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1373,8 +1373,12 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label)
#define VALIDATE_DESC(desc) do { \
if (!desc) \
return 0; \
if (IS_ERR(desc)) { \
pr_warn("%s: invalid GPIO (errorpointer)\n", __func__); \
return PTR_ERR(desc); \
} \
if (!desc->gdev) { \
pr_warn("%s: invalid GPIO\n", __func__); \
pr_warn("%s: invalid GPIO (no device)\n", __func__); \
return -EINVAL; \
} \
if ( !desc->gdev->chip ) { \
Expand All @@ -1386,8 +1390,12 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label)
#define VALIDATE_DESC_VOID(desc) do { \
if (!desc) \
return; \
if (IS_ERR(desc)) { \
pr_warn("%s: invalid GPIO (errorpointer)\n", __func__); \
return; \
} \
if (!desc->gdev) { \
pr_warn("%s: invalid GPIO\n", __func__); \
pr_warn("%s: invalid GPIO (no device)\n", __func__); \
return; \
} \
if (!desc->gdev->chip) { \
Expand Down Expand Up @@ -2061,7 +2069,7 @@ int gpiod_to_irq(const struct gpio_desc *desc)
* requires this function to not return zero on an invalid descriptor
* 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;

chip = desc->gdev->chip;
Expand Down

0 comments on commit bfbbe44

Please sign in to comment.