linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: sysfs: repair export returning -EPERM on 1st attempt
@ 2024-03-07 21:43 Alexander Sverdlin
  2024-03-08  9:32 ` Bartosz Golaszewski
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Sverdlin @ 2024-03-07 21:43 UTC (permalink / raw)
  To: linux-gpio
  Cc: Alexander Sverdlin, Bartosz Golaszewski, Andy Shevchenko, linux-kernel

It would make sense to return -EPERM if the bit was already set (already
used), not if it was cleared. Before this fix pins can only be exported on
the 2nd attempt:

$ echo 522 > /sys/class/gpio/export 
sh: write error: Operation not permitted
$ echo 522 > /sys/class/gpio/export 

Fixes: 35b545332b80 ("gpio: remove gpio_lock")
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
---
 drivers/gpio/gpiolib-sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 67fc09a57f26..6853ecd98bcb 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -593,7 +593,7 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
 	if (!guard.gc)
 		return -ENODEV;
 
-	if (!test_and_set_bit(FLAG_EXPORT, &desc->flags))
+	if (test_and_set_bit(FLAG_EXPORT, &desc->flags))
 		return -EPERM;
 
 	gdev = desc->gdev;
-- 
2.43.2


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

* Re: [PATCH] gpio: sysfs: repair export returning -EPERM on 1st attempt
  2024-03-07 21:43 [PATCH] gpio: sysfs: repair export returning -EPERM on 1st attempt Alexander Sverdlin
@ 2024-03-08  9:32 ` Bartosz Golaszewski
  0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2024-03-08  9:32 UTC (permalink / raw)
  To: Alexander Sverdlin; +Cc: linux-gpio, Andy Shevchenko, linux-kernel

On Thu, Mar 7, 2024 at 10:43 PM Alexander Sverdlin
<alexander.sverdlin@gmail.com> wrote:
>
> It would make sense to return -EPERM if the bit was already set (already
> used), not if it was cleared. Before this fix pins can only be exported on
> the 2nd attempt:
>
> $ echo 522 > /sys/class/gpio/export
> sh: write error: Operation not permitted
> $ echo 522 > /sys/class/gpio/export
>
> Fixes: 35b545332b80 ("gpio: remove gpio_lock")
> Signed-off-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
> ---
>  drivers/gpio/gpiolib-sysfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
> index 67fc09a57f26..6853ecd98bcb 100644
> --- a/drivers/gpio/gpiolib-sysfs.c
> +++ b/drivers/gpio/gpiolib-sysfs.c
> @@ -593,7 +593,7 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
>         if (!guard.gc)
>                 return -ENODEV;
>
> -       if (!test_and_set_bit(FLAG_EXPORT, &desc->flags))
> +       if (test_and_set_bit(FLAG_EXPORT, &desc->flags))
>                 return -EPERM;
>
>         gdev = desc->gdev;
> --
> 2.43.2
>

That's of course correct. Applied.

Bart

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

end of thread, other threads:[~2024-03-08  9:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-07 21:43 [PATCH] gpio: sysfs: repair export returning -EPERM on 1st attempt Alexander Sverdlin
2024-03-08  9:32 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).