linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/1] gpiolib: sysfs: Do unexport GPIO when user asks for it
@ 2023-08-14 11:26 Andy Shevchenko
  2023-08-14 16:13 ` Bartosz Golaszewski
  2023-08-16 21:33 ` Linus Walleij
  0 siblings, 2 replies; 5+ messages in thread
From: Andy Shevchenko @ 2023-08-14 11:26 UTC (permalink / raw)
  To: Andy Shevchenko, linux-gpio, linux-kernel
  Cc: Linus Walleij, Bartosz Golaszewski, Andy Shevchenko,
	Marek Behún

It seems that sysfs interface implicitly relied on the gpiod_free()
to unexport the line. This is not good and prone to regressions.
Fix it by explicitly calling gpiod_unexport().

Fixes: b0ce9ce408b6 ("gpiolib: Do not unexport GPIO on freeing")
Reported-by: Marek Behún <kabel@kernel.org>
Closes: https://lore.kernel.org/r/20230808102828.4a9eac09@dellmb
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Marek Behún <kabel@kernel.org>
---
 drivers/gpio/gpiolib-sysfs.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 530dfd19d7b5..50503a4525eb 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -515,8 +515,9 @@ static ssize_t unexport_store(const struct class *class,
 	 * they may be undone on its behalf too.
 	 */
 	if (test_and_clear_bit(FLAG_SYSFS, &desc->flags)) {
+		gpiod_unexport(desc);
+		gpiod_free(desc);
 		status = 0;
-		gpiod_free(desc);
 	}
 done:
 	if (status)
@@ -781,8 +782,10 @@ void gpiochip_sysfs_unregister(struct gpio_device *gdev)
 	mutex_unlock(&sysfs_lock);
 
 	/* unregister gpiod class devices owned by sysfs */
-	for_each_gpio_desc_with_flag(chip, desc, FLAG_SYSFS)
+	for_each_gpio_desc_with_flag(chip, desc, FLAG_SYSFS) {
+		gpiod_unexport(desc);
 		gpiod_free(desc);
+	}
 }
 
 static int __init gpiolib_sysfs_init(void)
-- 
2.40.0.1.gaa8946217a0b


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

* Re: [PATCH v1 1/1] gpiolib: sysfs: Do unexport GPIO when user asks for it
  2023-08-14 11:26 [PATCH v1 1/1] gpiolib: sysfs: Do unexport GPIO when user asks for it Andy Shevchenko
@ 2023-08-14 16:13 ` Bartosz Golaszewski
  2023-08-14 16:28   ` Andy Shevchenko
  2023-08-16 21:33 ` Linus Walleij
  1 sibling, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2023-08-14 16:13 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-gpio, linux-kernel, Linus Walleij, Andy Shevchenko,
	Marek Behún

On Mon, Aug 14, 2023 at 1:19 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> It seems that sysfs interface implicitly relied on the gpiod_free()
> to unexport the line. This is not good and prone to regressions.
> Fix it by explicitly calling gpiod_unexport().
>

I wouldn't say it's prone to regressions, it's literally just that
gpiod_free() should not deal with sysfs.

How about that for commit message (I can change it when applying):

It seems that sysfs interface implicitly relied on the gpiod_free()
to unexport the line. This is logically incorrect as core gpiolib should
not deal with sysfs so instead of restoring it, let's call gpiod_unexport()
from sysfs code.

Bart

> Fixes: b0ce9ce408b6 ("gpiolib: Do not unexport GPIO on freeing")
> Reported-by: Marek Behún <kabel@kernel.org>
> Closes: https://lore.kernel.org/r/20230808102828.4a9eac09@dellmb
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Tested-by: Marek Behún <kabel@kernel.org>
> ---
>  drivers/gpio/gpiolib-sysfs.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
> index 530dfd19d7b5..50503a4525eb 100644
> --- a/drivers/gpio/gpiolib-sysfs.c
> +++ b/drivers/gpio/gpiolib-sysfs.c
> @@ -515,8 +515,9 @@ static ssize_t unexport_store(const struct class *class,
>          * they may be undone on its behalf too.
>          */
>         if (test_and_clear_bit(FLAG_SYSFS, &desc->flags)) {
> +               gpiod_unexport(desc);
> +               gpiod_free(desc);
>                 status = 0;
> -               gpiod_free(desc);
>         }
>  done:
>         if (status)
> @@ -781,8 +782,10 @@ void gpiochip_sysfs_unregister(struct gpio_device *gdev)
>         mutex_unlock(&sysfs_lock);
>
>         /* unregister gpiod class devices owned by sysfs */
> -       for_each_gpio_desc_with_flag(chip, desc, FLAG_SYSFS)
> +       for_each_gpio_desc_with_flag(chip, desc, FLAG_SYSFS) {
> +               gpiod_unexport(desc);
>                 gpiod_free(desc);
> +       }
>  }
>
>  static int __init gpiolib_sysfs_init(void)
> --
> 2.40.0.1.gaa8946217a0b
>

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

* Re: [PATCH v1 1/1] gpiolib: sysfs: Do unexport GPIO when user asks for it
  2023-08-14 16:13 ` Bartosz Golaszewski
@ 2023-08-14 16:28   ` Andy Shevchenko
  2023-08-16 11:36     ` Bartosz Golaszewski
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2023-08-14 16:28 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Andy Shevchenko, linux-gpio, linux-kernel, Linus Walleij,
	Andy Shevchenko, Marek Behún

On Mon, Aug 14, 2023 at 7:13 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> On Mon, Aug 14, 2023 at 1:19 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > It seems that sysfs interface implicitly relied on the gpiod_free()
> > to unexport the line. This is not good and prone to regressions.
> > Fix it by explicitly calling gpiod_unexport().
> >
>
> I wouldn't say it's prone to regressions, it's literally just that
> gpiod_free() should not deal with sysfs.
>
> How about that for commit message (I can change it when applying):
>
> It seems that sysfs interface implicitly relied on the gpiod_free()
> to unexport the line. This is logically incorrect as core gpiolib should
> not deal with sysfs so instead of restoring it, let's call gpiod_unexport()
> from sysfs code.

I'm fine with it, go ahead and apply with the change. Thank you!

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH v1 1/1] gpiolib: sysfs: Do unexport GPIO when user asks for it
  2023-08-14 16:28   ` Andy Shevchenko
@ 2023-08-16 11:36     ` Bartosz Golaszewski
  0 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2023-08-16 11:36 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Andy Shevchenko, linux-gpio, linux-kernel, Linus Walleij,
	Andy Shevchenko, Marek Behún

On Mon, Aug 14, 2023 at 6:29 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Mon, Aug 14, 2023 at 7:13 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> > On Mon, Aug 14, 2023 at 1:19 PM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > >
> > > It seems that sysfs interface implicitly relied on the gpiod_free()
> > > to unexport the line. This is not good and prone to regressions.
> > > Fix it by explicitly calling gpiod_unexport().
> > >
> >
> > I wouldn't say it's prone to regressions, it's literally just that
> > gpiod_free() should not deal with sysfs.
> >
> > How about that for commit message (I can change it when applying):
> >
> > It seems that sysfs interface implicitly relied on the gpiod_free()
> > to unexport the line. This is logically incorrect as core gpiolib should
> > not deal with sysfs so instead of restoring it, let's call gpiod_unexport()
> > from sysfs code.
>
> I'm fine with it, go ahead and apply with the change. Thank you!
>
> --
> With Best Regards,
> Andy Shevchenko

Queued for fixes.

Bart

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

* Re: [PATCH v1 1/1] gpiolib: sysfs: Do unexport GPIO when user asks for it
  2023-08-14 11:26 [PATCH v1 1/1] gpiolib: sysfs: Do unexport GPIO when user asks for it Andy Shevchenko
  2023-08-14 16:13 ` Bartosz Golaszewski
@ 2023-08-16 21:33 ` Linus Walleij
  1 sibling, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2023-08-16 21:33 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski, Andy Shevchenko,
	Marek Behún

On Mon, Aug 14, 2023 at 1:19 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> It seems that sysfs interface implicitly relied on the gpiod_free()
> to unexport the line. This is not good and prone to regressions.
> Fix it by explicitly calling gpiod_unexport().
>
> Fixes: b0ce9ce408b6 ("gpiolib: Do not unexport GPIO on freeing")
> Reported-by: Marek Behún <kabel@kernel.org>
> Closes: https://lore.kernel.org/r/20230808102828.4a9eac09@dellmb
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Tested-by: Marek Behún <kabel@kernel.org>

Late to the show so patch already applied, but THANKS for
drilling into it and smoking out this bug Andy.

Yours,
Linus Walleij

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

end of thread, other threads:[~2023-08-16 21:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-14 11:26 [PATCH v1 1/1] gpiolib: sysfs: Do unexport GPIO when user asks for it Andy Shevchenko
2023-08-14 16:13 ` Bartosz Golaszewski
2023-08-14 16:28   ` Andy Shevchenko
2023-08-16 11:36     ` Bartosz Golaszewski
2023-08-16 21:33 ` Linus Walleij

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).