[PATCH] gpio: sysfs: add missing mutex_destroy()

From: Bartosz Golaszewski
Date: Fri May 16 2025 - 06:40:40 EST


From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>

We initialize the data->mutex in gpiod_export() but lack the
corresponding mutex_destroy() in gpiod_unexport() causing a resource
leak with mutex debugging enabled. Add the call right before kfreeing
the GPIO data.

Fixes: 6ffcb7971486 ("gpio: sysfs: use per-gpio locking")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
---
drivers/gpio/gpiolib-sysfs.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 4a3aa09dad9d..cd3381a4bc93 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -713,6 +713,7 @@ void gpiod_unexport(struct gpio_desc *desc)
}

put_device(dev);
+ mutex_destroy(&data->mutex);
kfree(data);
}
EXPORT_SYMBOL_GPL(gpiod_unexport);
--
2.45.2