diff mbox

gpio: make sure gpiod_to_irq() returns negative on NULL desc

Message ID 1466024604-28014-1-git-send-email-linus.walleij@linaro.org
State Accepted
Commit 79bb71bd1d93197ce227fa167b450b633f30a52b
Headers show

Commit Message

Linus Walleij June 15, 2016, 9:03 p.m. UTC
commit 54d77198fdfbc4f0fe11b4252c1d9c97d51a3264
("gpio: bail out silently on NULL descriptors")
doesn't work for gpiod_to_irq(): drivers assume that NULL
descriptors will give negative IRQ numbers in return.

It has been pointed out that returning 0 is NO_IRQ and that
drivers should be amended to treat this as an error, but that
is for the longer term: now let us repair the semantics.

Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
Reported-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

---
 drivers/gpio/gpiolib.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

-- 
2.4.11

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Linus Walleij June 17, 2016, 4:13 p.m. UTC | #1
On Fri, Jun 17, 2016 at 6:09 PM, Hans de Goede <hdegoede@redhat.com> wrote:
> On 15-06-16 23:03, Linus Walleij wrote:

>>

>> commit 54d77198fdfbc4f0fe11b4252c1d9c97d51a3264

>> ("gpio: bail out silently on NULL descriptors")

>> doesn't work for gpiod_to_irq(): drivers assume that NULL

>> descriptors will give negative IRQ numbers in return.

>>

>> It has been pointed out that returning 0 is NO_IRQ and that

>> drivers should be amended to treat this as an error, but that

>> is for the longer term: now let us repair the semantics.

>>

>> Cc: Maxime Ripard <maxime.ripard@free-electrons.com>

>> Reported-by: Hans de Goede <hdegoede@redhat.com>

>> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

>

>

> I can confirm that this fixes the problem for me:

>

> Tested-by: Hans de Goede <hdegoede@redhat.com>


Thanks, applied for fixes and pushed for linux-next.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 58d822d7e8da..f39bf05993e7 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2056,7 +2056,14 @@  int gpiod_to_irq(const struct gpio_desc *desc)
 	struct gpio_chip *chip;
 	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 || !desc->gdev || !desc->gdev->chip)
+		return -EINVAL;
+
 	chip = desc->gdev->chip;
 	offset = gpio_chip_hwgpio(desc);
 	if (chip->to_irq) {