Skip to content

Commit 3e13eee

Browse files
committed
Merge tag 'gpio-fixes-for-v6.5-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux
Pull gpio fixes from Bartosz Golaszewski: - fix a regression in the sysfs interface - fix a reference counting bug that's been around for years - MAINTAINERS update * tag 'gpio-fixes-for-v6.5-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: gpiolib: fix reference leaks when removing GPIO chips still in use gpiolib: sysfs: Do unexport GPIO when user asks for it MAINTAINERS: add content regex for gpio-regmap
2 parents 8abd728 + 3386fb8 commit 3e13eee

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8812,6 +8812,7 @@ R: Michael Walle <michael@walle.cc>
88128812
S: Maintained
88138813
F: drivers/gpio/gpio-regmap.c
88148814
F: include/linux/gpio/regmap.h
8815+
K: (devm_)?gpio_regmap_(un)?register
88158816

88168817
GPIO SUBSYSTEM
88178818
M: Linus Walleij <linus.walleij@linaro.org>

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)

drivers/gpio/gpiolib.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,12 +2167,18 @@ static bool gpiod_free_commit(struct gpio_desc *desc)
21672167

21682168
void gpiod_free(struct gpio_desc *desc)
21692169
{
2170-
if (desc && desc->gdev && gpiod_free_commit(desc)) {
2171-
module_put(desc->gdev->owner);
2172-
gpio_device_put(desc->gdev);
2173-
} else {
2170+
/*
2171+
* We must not use VALIDATE_DESC_VOID() as the underlying gdev->chip
2172+
* may already be NULL but we still want to put the references.
2173+
*/
2174+
if (!desc)
2175+
return;
2176+
2177+
if (!gpiod_free_commit(desc))
21742178
WARN_ON(extra_checks);
2175-
}
2179+
2180+
module_put(desc->gdev->owner);
2181+
gpio_device_put(desc->gdev);
21762182
}
21772183

21782184
/**

0 commit comments

Comments
 (0)