[PATCH] gpio: sysfs: free the chip attribute group name on unexport
From: Arun Iyengar via B4 Relay
Date: Mon Nov 30 2026 - 15:20:32 EST
From: Arun Iyengar <aiyengar1990@xxxxxxxxx>
gpiod_export() allocates chip_attr_group.name but gpiod_unexport()
never frees it, leaking it on every unexport.
Fixes: 4fa93223e03e ("gpio: sysfs: export the GPIO directory locally in the gpiochip<id> directory")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>
---
Found with kmemleak on an Orange Pi 5. 1000 sysfs export/unexport
cycles: 809 leaked names before, 0 after.
Developed with Claude (Anthropic), which wrote the code and the commit
message. I reviewed the change.
---
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 08f514992569..d0798b3f5383 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -958,6 +958,7 @@ static void gpiod_unexport_unlocked(struct gpio_desc *desc)
sysfs_remove_groups(desc_data->parent,
desc_data->chip_attr_groups);
+ kfree(desc_data->chip_attr_group.name);
mutex_destroy(&desc_data->mutex);
kfree(desc_data);
---
base-commit: 838e2af4fde3f180abdd0e4755be078be7e132a1
change-id: 20261129-gpio-sysfs-unexport-leak-4ebc3b9a7179
Best regards,
--
Arun Iyengar <aiyengar1990@xxxxxxxxx>