]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
gpiolib: don't dereference a desc before validation
authorVladimir Zapolskiy <vz@mleia.com>
Thu, 21 Dec 2017 16:37:24 +0000 (18:37 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 12 Apr 2018 10:31:04 +0000 (12:31 +0200)
[ Upstream commit 30322bcf82d74cad0d6e1cf9ba7fa7fa48c7a026 ]

The fix restores a proper validation of an input gpio desc, which
might be needed to deal with optional GPIOs correctly.

Fixes: 02e479808b5d ("gpio: Alter semantics of *raw* operations to actually be raw")
Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpio/gpiolib.c

index 7a5cf5b08c54f16218f58aeffb7360db14c0345e..00d0060435856c716b8ff5fc2620679c5ceb88b0 100644 (file)
@@ -2468,7 +2468,7 @@ EXPORT_SYMBOL_GPL(gpiod_direction_output_raw);
  */
 int gpiod_direction_output(struct gpio_desc *desc, int value)
 {
-       struct gpio_chip *gc = desc->gdev->chip;
+       struct gpio_chip *gc;
        int ret;
 
        VALIDATE_DESC(desc);
@@ -2485,6 +2485,7 @@ int gpiod_direction_output(struct gpio_desc *desc, int value)
                return -EIO;
        }
 
+       gc = desc->gdev->chip;
        if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) {
                /* First see if we can enable open drain in hardware */
                ret = gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc),