public inbox for linux-gpio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpiolib: remove redundant callback check
@ 2026-01-09 10:55 Bartosz Golaszewski
  2026-01-09 14:05 ` Michael Walle
  2026-01-12  8:41 ` Bartosz Golaszewski
  0 siblings, 2 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2026-01-09 10:55 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: linux-kernel, linux-gpio, Bartosz Golaszewski, Michael Walle

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 <mwalle@kernel.org>
Closes: https://lore.kernel.org/all/DFJAFK3DTBOZ.3G2P3A5IH34GF@kernel.org/
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
 drivers/gpio/gpiolib.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 0a14085f3871..5eb918da7ea2 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] gpiolib: remove redundant callback check
  2026-01-09 10:55 [PATCH] gpiolib: remove redundant callback check Bartosz Golaszewski
@ 2026-01-09 14:05 ` Michael Walle
  2026-01-09 14:36   ` Bartosz Golaszewski
  2026-01-12  8:41 ` Bartosz Golaszewski
  1 sibling, 1 reply; 4+ messages in thread
From: Michael Walle @ 2026-01-09 14:05 UTC (permalink / raw)
  To: Bartosz Golaszewski, Linus Walleij, Bartosz Golaszewski
  Cc: linux-kernel, linux-gpio

[-- Attachment #1: Type: text/plain, Size: 1358 bytes --]

Hi,

On Fri Jan 9, 2026 at 11:55 AM CET, Bartosz Golaszewski wrote:
> 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 <mwalle@kernel.org>
> Closes: https://lore.kernel.org/all/DFJAFK3DTBOZ.3G2P3A5IH34GF@kernel.org/
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
> ---
>  drivers/gpio/gpiolib.c | 3 ---
>  1 file changed, 3 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 0a14085f3871..5eb918da7ea2 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -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.

>  	ret = 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

>  	if (ret < 0)
>  		return ret;


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 297 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] gpiolib: remove redundant callback check
  2026-01-09 14:05 ` Michael Walle
@ 2026-01-09 14:36   ` Bartosz Golaszewski
  0 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2026-01-09 14:36 UTC (permalink / raw)
  To: Michael Walle
  Cc: linux-kernel, linux-gpio, Bartosz Golaszewski, Linus Walleij,
	Bartosz Golaszewski

On Fri, 9 Jan 2026 15:05:36 +0100, Michael Walle <mwalle@kernel.org> said:
> Hi,
>
> On Fri Jan 9, 2026 at 11:55 AM CET, Bartosz Golaszewski wrote:
>> 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 <mwalle@kernel.org>
>> Closes: https://lore.kernel.org/all/DFJAFK3DTBOZ.3G2P3A5IH34GF@kernel.org/
>> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
>> ---
>>  drivers/gpio/gpiolib.c | 3 ---
>>  1 file changed, 3 deletions(-)
>>
>> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
>> index 0a14085f3871..5eb918da7ea2 100644
>> --- a/drivers/gpio/gpiolib.c
>> +++ b/drivers/gpio/gpiolib.c
>> @@ -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.
>
>>  	ret = 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/20260109130832.27326-1-bartosz.golaszewski@oss.qualcomm.com/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] gpiolib: remove redundant callback check
  2026-01-09 10:55 [PATCH] gpiolib: remove redundant callback check Bartosz Golaszewski
  2026-01-09 14:05 ` Michael Walle
@ 2026-01-12  8:41 ` Bartosz Golaszewski
  1 sibling, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2026-01-12  8:41 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Bartosz Golaszewski
  Cc: linux-kernel, linux-gpio, Michael Walle


On Fri, 09 Jan 2026 11:55:56 +0100, Bartosz Golaszewski wrote:
> 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,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-12  8:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-09 10:55 [PATCH] gpiolib: remove redundant callback check Bartosz Golaszewski
2026-01-09 14:05 ` Michael Walle
2026-01-09 14:36   ` Bartosz Golaszewski
2026-01-12  8:41 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox