Commit 144b5ae3 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'gpio-v4.7-4' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio

Pull GPIO fixes from Linus Walleij:
 "More GPIO fixes.  Most prominent the gpiod_to_irq() fix brought to my
  attention by Hans de Goede.  The hardening patch is a consequence of
  the reasoning around that bug.

   - It was discovered that too many parts of the kernel does not
     respect gpiod_to_irq() returning zero for an invalid IRQ.  While
     this gets fixed, we need to make it return negative errorcodes
     again.

   - Harden the library a bit when passed error pointers.  It is a bug
     to use these, but let's be helpful and warn the users.

   - Fix an uninitialized spinlock in the 104-idi-48 driver"

* tag 'gpio-v4.7-4' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio:
  gpio: make library immune to error pointers
  gpio: make sure gpiod_to_irq() returns negative on NULL desc
  gpio: 104-idi-48: Fix missing spin_lock_init for ack_lock
parents 67016f6c bfbbe44d
...@@ -247,6 +247,7 @@ static int idi_48_probe(struct device *dev, unsigned int id) ...@@ -247,6 +247,7 @@ static int idi_48_probe(struct device *dev, unsigned int id)
idi48gpio->irq = irq[id]; idi48gpio->irq = irq[id];
spin_lock_init(&idi48gpio->lock); spin_lock_init(&idi48gpio->lock);
spin_lock_init(&idi48gpio->ack_lock);
dev_set_drvdata(dev, idi48gpio); dev_set_drvdata(dev, idi48gpio);
......
...@@ -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) { \
...@@ -2056,7 +2064,14 @@ int gpiod_to_irq(const struct gpio_desc *desc) ...@@ -2056,7 +2064,14 @@ int gpiod_to_irq(const struct gpio_desc *desc)
struct gpio_chip *chip; struct gpio_chip *chip;
int offset; int offset;
VALIDATE_DESC(desc); /*
* Cannot VALIDATE_DESC() here as gpiod_to_irq() consumer semantics
* requires this function to not return zero on an invalid descriptor
* but rather a negative error number.
*/
if (!desc || IS_ERR(desc) || !desc->gdev || !desc->gdev->chip)
return -EINVAL;
chip = desc->gdev->chip; chip = desc->gdev->chip;
offset = gpio_chip_hwgpio(desc); offset = gpio_chip_hwgpio(desc);
if (chip->to_irq) { if (chip->to_irq) {
......
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