diff mbox series

gpiolib: don't dereference a desc before validation

Message ID 20171221163724.6043-1-vz@mleia.com
State New
Headers show
Series gpiolib: don't dereference a desc before validation | expand

Commit Message

Vladimir Zapolskiy Dec. 21, 2017, 4:37 p.m. UTC
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>
---
 drivers/gpio/gpiolib.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Linus Walleij Jan. 2, 2018, 8:32 a.m. UTC | #1
On Thu, Dec 21, 2017 at 5:37 PM, Vladimir Zapolskiy <vz@mleia.com> wrote:

> 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>

Hm you're right this looks better.

I don't think it's a regression so queued as a non-critical fix.

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 series

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index e9ec44f..72577cd 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2457,7 +2457,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);
@@ -2474,6 +2474,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),