gpio: generic: clamp retured value to [0,1]
authorLinus Walleij <linus.walleij@linaro.org>
Wed, 5 Feb 2014 13:08:02 +0000 (14:08 +0100)
committerLinus Walleij <linus.walleij@linaro.org>
Thu, 6 Feb 2014 09:33:48 +0000 (10:33 +0100)
The generic GPIO would return 0 for low generic GPIO, and
something != 0 for high GPIO. Let's make this sane by clamping
the returned value to [0,1].

Reported-by: Evgeny Boger <boger@contactless.ru>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpio-generic.c

index 8c778af..d815dd2 100644 (file)
@@ -139,7 +139,7 @@ static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
 {
        struct bgpio_chip *bgc = to_bgpio_chip(gc);
 
-       return bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio);
+       return !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio));
 }
 
 static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)