mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: Linus Walleij <linusw@kernel.org>,
	 Bartosz Golaszewski <brgl@kernel.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	 stable@vger.kernel.org, Arun Iyengar <aiyengar1990@gmail.com>
Subject: [PATCH] gpio: sysfs: free the chip attribute group name on unexport
Date: Mon, 30 Nov 2026 20:20:19 +0000	[thread overview]
Message-ID: <20261130-gpio-sysfs-unexport-leak-v1-1-cbee5951fb00@gmail.com> (raw)

From: Arun Iyengar <aiyengar1990@gmail.com>

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@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
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@gmail.com>



                 reply	other threads:[~2026-11-30 20:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130-gpio-sysfs-unexport-leak-v1-1-cbee5951fb00@gmail.com \
    --to=devnull+aiyengar1990.gmail.com@kernel.org \
    --cc=aiyengar1990@gmail.com \
    --cc=brgl@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®