gpiolib: remove redundant callback check
PATCH 1/1 gpiolib: remove redundant callback check
The presence of the .get_direction() callback is already checked in gpiochip_get_direction(). Remove the duplicated check which also returns the wrong error code to user-space.
--- drivers/gpio/gpiolib.c | 3 --- 1 file changed, 3 deletions(-)
drivers/gpio/gpiolib.c +0 -3
@@ -468,9 +468,6 @@ int gpiod_get_direction(struct gpio_desc *desc) test_bit(GPIOD_FLAG_IS_OUT, &flags))return 0 ; -if (!guard.gc->get_direction) -return -ENOTSUPP ; - ret =gpiochip_get_direction (guard.gc, offset);if (ret <0 )return ret;
Signature · 1 line
2.47.3
Hi,
Quoted 17 lines · Bartosz Golaszewski
The presence of the .get_direction() callback is already checked in
gpiochip_get_direction(). Remove the duplicated check which also returns the wrong error code to user-space.Fixes e623c4303ed1 ("gpiolib: sanitize the return value of gpio_chip::get_direction()")Reported-by Michael Walle <[email protected]>Signed-off-by Bartosz Golaszewski <[email protected]>--- drivers/gpio/gpiolib.c | 3 --- 1 file changed, 3 deletions(-)drivers/gpio/gpiolib.c +0
-0
drivers/gpio/gpiolib.c int gpiod_get_direction(struct gpio_desc *desc) · line 473
Quoted 6 lines
drivers/gpio/gpiolib.c +0
-3@@ -468,9 +468,6 @@ int gpiod_get_direction(struct gpio_desc *desc) test_bit(GPIOD_FLAG_IS_OUT, &flags))return 0 ; -if (!guard.gc->get_direction) -return -ENOTSUPP ; -
Not sure, if that will make it better or worse though.
drivers/gpio/gpiolib.c int gpiod_get_direction(struct gpio_desc *desc) · line 471
Quoted 1 line
drivers/gpio/gpiolib.c +0
-0ret =gpiochip_get_direction (guard.gc, offset);
Because that will then do a WARN_ON(!.get_direction) and will spam the kernel log in case of the gpio-shared-proxy. Also the return code will change from ENOTSUPP to EOPNOTSUPP.
-michael
Quoted 2 lines
drivers/gpio/gpiolib.c +0
-0if (ret <0 )return ret;
Bartosz Golaszewski
maintainerQuoted 29 lines · Michael Walle
Hi,
Quoted 17 lines · Bartosz Golaszewski
The presence of the .get_direction() callback is already checked in
gpiochip_get_direction(). Remove the duplicated check which also returns the wrong error code to user-space.Fixes e623c4303ed1 ("gpiolib: sanitize the return value of gpio_chip::get_direction()")Reported-by Michael Walle <[email protected]>Signed-off-by Bartosz Golaszewski <[email protected]>--- drivers/gpio/gpiolib.c | 3 --- 1 file changed, 3 deletions(-)drivers/gpio/gpiolib.c +0
-0drivers/gpio/gpiolib.c int gpiod_get_direction(struct gpio_desc *desc) · line 473
Quoted 6 lines
drivers/gpio/gpiolib.c +0
-3@@ -468,9 +468,6 @@ int gpiod_get_direction(struct gpio_desc *desc) test_bit(GPIOD_FLAG_IS_OUT, &flags))return 0 ; -if (!guard.gc->get_direction) -return -ENOTSUPP ; -Not sure, if that will make it better or worse though.
Quoted 6 lines
drivers/gpio/gpiolib.c int gpiod_get_direction(struct gpio_desc *desc) · line 471
Quoted 1 line
drivers/gpio/gpiolib.c +0
-0ret =gpiochip_get_direction (guard.gc, offset);Because that will then do a
WARN_ON(!.get_direction)and will spam the kernel log in case of the gpio-shared-proxy. Also the return code will change from ENOTSUPP to EOPNOTSUPP.
From checkpatch.pl:
--
# ENOTSUPP is not a standard error code and should be avoided in new patches. # Folks usually mean EOPNOTSUPP (also called ENOTSUP), when they type ENOTSUPP. --
This can end up propagated to user-space which doesn't know what ENOTSUPP is. This is why we've already changed the return code to -EOPNOTSUPP before, this is just a leftover.
I prefer to keep the WARN() because it's very unusual for a GPIO driver to not implement this callback. Can you confirm you're still seeing the issue with this patch[1]? If so, let's use [2] as the fix?
Bart
[1] https://lore.kernel.org/all/20260108-gpio-shared-false-positive-v1-1-5dbf8d1b2f7d@oss.qualcomm.com/
[2] https://lore.kernel.org/all/[email protected]/
Bartosz Golaszewski
AppliedQuoted 5 lines · Bartosz Golaszewski
The presence of the .get_direction() callback is already checked in
gpiochip_get_direction(). Remove the duplicated check which also returns the wrong error code to user-space.
Applied, thanks!
[1/1] gpiolib: remove redundant callback check
commit: 471e998c0e31206ff0eac7202b2659698cf9b46e
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>