Skip to content

Commit 39243ee

Browse files
linuswrichardweinberger
authored andcommitted
gpio: make sure gpiod_to_irq() returns negative on NULL desc
commit 54d7719 ("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> Tested-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 0b305cc commit 39243ee

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/gpio/gpiolib.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,14 @@ int gpiod_to_irq(const struct gpio_desc *desc)
20562056
struct gpio_chip *chip;
20572057
int offset;
20582058

2059-
VALIDATE_DESC(desc);
2059+
/*
2060+
* Cannot VALIDATE_DESC() here as gpiod_to_irq() consumer semantics
2061+
* requires this function to not return zero on an invalid descriptor
2062+
* but rather a negative error number.
2063+
*/
2064+
if (!desc || !desc->gdev || !desc->gdev->chip)
2065+
return -EINVAL;
2066+
20602067
chip = desc->gdev->chip;
20612068
offset = gpio_chip_hwgpio(desc);
20622069
if (chip->to_irq) {

0 commit comments

Comments
 (0)