All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lin Tzu Yang <rongh7426@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] iio: dummy: free the sw device on configfs release
Date: Wed,  2 Dec 2026 18:13:13 +0800	[thread overview]
Message-ID: <20261202101313.944902-1-rongh7426@gmail.com> (raw)

iio_dummy_probe() allocates the struct iio_sw_device that embeds the
configfs group of a dummy device, but nothing frees it:
iio_dummy_remove() frees the iio_dev only, and iio_dummy_type has no
->release(). Every mkdir/rmdir of a directory under
/sys/kernel/config/iio/devices/dummy/ leaks it.

Free it from the ->release() callback of the config_item_type, which
configfs calls when the last reference to the item is dropped, as
commit 8fb20cdf9c86 ("iio: trigger: free hrtimer and loop triggers on
configfs release") does for the software triggers.

Fixes: 3d85fb6f8104 ("iio: dummy: Convert IIO dummy to configfs")
Signed-off-by: Lin Tzu Yang <rongh7426@gmail.com>
---
Tested in a QEMU/KVM arm64 guest with kmemleak and KASAN, on
configfs-next 2e0fad9d2eae, where this file is the same as on
fixes-togreg. After 50 mkdir/rmdir pairs of a dummy device, kmemleak
reported 29 unreferenced 192-byte objects allocated in
iio_dummy_probe() before the patch, and none after. Removing a dummy
device while its character device is open still works: reads from the
open file fail afterwards, with no KASAN reports.

The patch is against fixes-togreg, on top of 8fb20cdf9c86.

This patch was written with the help of an AI coding assistant
(Claude). I ran the tests above and reviewed the change.

 drivers/iio/dummy/iio_simple_dummy.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/iio/dummy/iio_simple_dummy.c b/drivers/iio/dummy/iio_simple_dummy.c
index 28ae1e7b59..2f3ea3b419 100644
--- a/drivers/iio/dummy/iio_simple_dummy.c
+++ b/drivers/iio/dummy/iio_simple_dummy.c
@@ -23,7 +23,17 @@
 #include <linux/iio/sw_device.h>
 #include "iio_simple_dummy.h"
 
+static void iio_dummy_release(struct config_item *item)
+{
+	kfree(to_iio_sw_device(item));
+}
+
+static const struct configfs_item_operations iio_dummy_item_ops = {
+	.release = iio_dummy_release,
+};
+
 static const struct config_item_type iio_dummy_type = {
+	.ct_item_ops = &iio_dummy_item_ops,
 	.ct_owner = THIS_MODULE,
 };
 
-- 
2.47.3


                 reply	other threads:[~2026-12-02 10:13 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=20261202101313.944902-1-rongh7426@gmail.com \
    --to=rongh7426@gmail.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.