[PATCH v6 1/5] gpio: shared: factor out per-entry teardown helper

From: Bartosz Golaszewski

Date: Wed Oct 21 2026 - 10:41:05 EST


Move the body of the loop in gpio_device_teardown_shared() into
gpio_shared_teardown_entry(). This is a preparation for unwinding a
partially completed gpiochip_setup_shared(), which will need to tear
down individual entries. No functional change.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
---
drivers/gpio/gpiolib-shared.c | 37 ++++++++++++++++++++++---------------
1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/drivers/gpio/gpiolib-shared.c b/drivers/gpio/gpiolib-shared.c
index 8c9ac9d9330490b17fb3936b8758beb97a308a15..64bb450f0a8461d214a45aa97e2474ff0d1857ce 100644
--- a/drivers/gpio/gpiolib-shared.c
+++ b/drivers/gpio/gpiolib-shared.c
@@ -517,6 +517,27 @@ static void gpio_shared_remove_adev(struct auxiliary_device *adev)
auxiliary_device_uninit(adev);
}

+static void gpio_shared_teardown_entry(struct gpio_device *gdev,
+ struct gpio_shared_entry *entry)
+{
+ struct gpio_shared_ref *ref;
+
+ 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);
+ kfree(ref->lookup->table[0].key);
+ kfree(ref->lookup->dev_id);
+ kfree(ref->lookup);
+ ref->lookup = NULL;
+ }
+
+ gpio_shared_remove_adev(&ref->adev);
+ }
+}
+
int gpiochip_setup_shared(struct gpio_chip *gc)
{
struct gpio_device *gdev = gc->gpiodev;
@@ -606,26 +627,12 @@ int gpiochip_setup_shared(struct gpio_chip *gc)
void gpio_device_teardown_shared(struct gpio_device *gdev)
{
struct gpio_shared_entry *entry;
- struct gpio_shared_ref *ref;

list_for_each_entry(entry, &gpio_shared_list, list) {
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);
- kfree(ref->lookup->table[0].key);
- kfree(ref->lookup->dev_id);
- kfree(ref->lookup);
- ref->lookup = NULL;
- }
-
- gpio_shared_remove_adev(&ref->adev);
- }
+ gpio_shared_teardown_entry(gdev, entry);
}
}


--
2.47.3