From: Linus Walleij Date: Wed, 5 Feb 2014 13:08:02 +0000 (+0100) Subject: gpio: generic: clamp retured value to [0,1] X-Git-Tag: v3.15-rc1~105^2~68 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=25b35da7f4cce82271859f1b6eabd9f3bd41a2bb;p=linux.git gpio: generic: clamp retured value to [0,1] 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 Reviewed-by: Alexandre Courbot Signed-off-by: Linus Walleij --- diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c index 8c778afdf49f..d815dd25eb47 100644 --- a/drivers/gpio/gpio-generic.c +++ b/drivers/gpio/gpio-generic.c @@ -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)