Skip to content

Commit

Permalink
gpio: generic: clamp values from bgpio_get_set()
Browse files Browse the repository at this point in the history
The bgpio_get_set() call should return a value clamped to [0,1],
the current code will return a negative value if reading
bit 31, which turns the value negative as this is a signed value
and thus gets interpreted as an error by the gpiolib core.
Found on the gpio-mxc but applies to any MMIO driver.

Cc: stable@vger.kernel.org # 4.3+
Cc: kernel@pengutronix.de
Cc: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Fixes:  e20538b ("gpio: Propagate errors from chip->get()")
Reported-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Linus Walleij committed Dec 17, 2015
1 parent 3a57e74 commit 67a76aa
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/gpio/gpio-generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio)
unsigned long pinmask = bgc->pin2mask(bgc, gpio);

if (bgc->dir & pinmask)
return bgc->read_reg(bgc->reg_set) & pinmask;
return !!(bgc->read_reg(bgc->reg_set) & pinmask);
else
return bgc->read_reg(bgc->reg_dat) & pinmask;
return !!(bgc->read_reg(bgc->reg_dat) & pinmask);
}

static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
Expand Down

0 comments on commit 67a76aa

Please sign in to comment.