From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx> We have existing macros for direction settings so we don't need to rely on the magic value of 1 in the retval check. Use readable logic that explicitly says we expect INPUT, OUTPUT or a negative errno and nothing else in gpiochip_get_direction(). Fixes: e623c4303ed1 ("gpiolib: sanitize the return value of gpio_chip::get_direction()") Suggested-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> Closes: https://lore.kernel.org/all/Z7yfTggRrk3K6srs@xxxxxxxxxxxxxxxxxx/ Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx> --- drivers/gpio/gpiolib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 0d325cc41af3..6f4efab237e6 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -352,7 +352,10 @@ static int gpiochip_get_direction(struct gpio_chip *gc, unsigned int offset) return -EOPNOTSUPP; ret = gc->get_direction(gc, offset); - if (ret > 1) + if (ret < 0) + return ret; + + if (ret != GPIO_LINE_DIRECTION_OUT && ret != GPIO_LINE_DIRECTION_IN) ret = -EBADE; return ret; -- 2.45.2