[PATCH v2 1/3] gpiolib: shared: remove the proxies before releasing the shared line
From: Adrian Ambrozewicz
Date: Fri Nov 27 2026 - 02:49:40 EST
Since commit 4918cc05137c ("gpio: shared: propagate configuration to
pinctrl"), gpio_device_teardown_shared() releases the shared line with
gpiod_free_commit() and only then removes the proxy devices. Until a
proxy is gone, its consumers can still drive the line through the
parent chip. The late error path of gpiochip_add_data_with_key()
calls gpio_device_teardown_shared() with the chip live, so there they
can. gpiochip_remove() calls it after numbing the chip, so those calls
fail until "gpiolib: release the chip's own lines before numbing it on
removal" moves the call ahead of the numbing.
Remove the proxies first, then release the line.
With that patch and without this one, a test-only log on a shared
gpio-sim line showed both proxies still bound when the line was
released; with this one, none.
Fixes: 4918cc05137c ("gpio: shared: propagate configuration to pinctrl")
Signed-off-by: Adrian Ambrozewicz <aambrozewicz@xxxxxxxxxx>
---
drivers/gpio/gpiolib-shared.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/gpio/gpiolib-shared.c b/drivers/gpio/gpiolib-shared.c
index f34315a2059a..c1e346a56177 100644
--- a/drivers/gpio/gpiolib-shared.c
+++ b/drivers/gpio/gpiolib-shared.c
@@ -611,9 +611,6 @@ void gpio_device_teardown_shared(struct gpio_device *gdev)
if (!device_match_fwnode(&gdev->dev, entry->fwnode))
continue;
- scoped_guard(mutex, &entry->lock)
- gpiod_free_commit(&gdev->descs[entry->offset]);
-
list_for_each_entry(ref, &entry->refs, list) {
if (ref->lookup) {
gpiod_remove_lookup_table(ref->lookup);
@@ -625,6 +622,10 @@ void gpio_device_teardown_shared(struct gpio_device *gdev)
gpio_shared_remove_adev(&ref->adev);
}
+
+ /* Release the line only once no proxy can drive it. */
+ scoped_guard(mutex, &entry->lock)
+ gpiod_free_commit(&gdev->descs[entry->offset]);
}
}
--
2.43.0