Skip to content

Commit 20d9b3b

Browse files
andy-shevBartosz Golaszewski
authored andcommitted
gpiolib: sysfs: Do unexport GPIO when user asks for it
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. Fixes: b0ce9ce ("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> [Bartosz: tweaked the commit message] Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
1 parent 2fc8d02 commit 20d9b3b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/gpio/gpiolib-sysfs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,9 @@ static ssize_t unexport_store(const struct class *class,
515515
* they may be undone on its behalf too.
516516
*/
517517
if (test_and_clear_bit(FLAG_SYSFS, &desc->flags)) {
518-
status = 0;
518+
gpiod_unexport(desc);
519519
gpiod_free(desc);
520+
status = 0;
520521
}
521522
done:
522523
if (status)
@@ -781,8 +782,10 @@ void gpiochip_sysfs_unregister(struct gpio_device *gdev)
781782
mutex_unlock(&sysfs_lock);
782783

783784
/* unregister gpiod class devices owned by sysfs */
784-
for_each_gpio_desc_with_flag(chip, desc, FLAG_SYSFS)
785+
for_each_gpio_desc_with_flag(chip, desc, FLAG_SYSFS) {
786+
gpiod_unexport(desc);
785787
gpiod_free(desc);
788+
}
786789
}
787790

788791
static int __init gpiolib_sysfs_init(void)

0 commit comments

Comments
 (0)