Commit cc78604f authored by Bartosz Golaszewski's avatar Bartosz Golaszewski
Browse files

gpiolib: use a more explicit retval logic in gpiochip_get_direction()



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: e623c430 ("gpiolib: sanitize the return value of gpio_chip::get_direction()")
Suggested-by: default avatarAndy Shevchenko <andriy.shevchenko@intel.com>
Closes: https://lore.kernel.org/all/Z7yfTggRrk3K6srs@black.fi.intel.com/


Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20250226-retval-fixes-v2-2-c8dc57182441@linaro.org


Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
parent 9becde08
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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;