* [PATCH] iio: dummy: free the sw device on configfs release
@ 2026-12-02 10:13 Lin Tzu Yang
0 siblings, 0 replies; only message in thread
From: Lin Tzu Yang @ 2026-12-02 10:13 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
linux-kernel
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-02 10:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 10:13 [PATCH] iio: dummy: free the sw device on configfs release Lin Tzu Yang
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.