[PATCH v4 1/2] fwctl: add device release hook

From: Zhi Wang

Date: Wed Jun 24 2026 - 05:21:52 EST


Add an optional per-device release callback to struct fwctl_device and
invoke it from fwctl_device_release() before kfree().

This gives higher-level abstractions a final teardown point for tail data
that requires explicit destruction.

Signed-off-by: Zhi Wang <zhiw@xxxxxxxxxx>
---
drivers/fwctl/main.c | 2 ++
include/linux/fwctl.h | 2 ++
2 files changed, 4 insertions(+)

diff --git a/drivers/fwctl/main.c b/drivers/fwctl/main.c
index 098c3824ad75..7bc76e3a5306 100644
--- a/drivers/fwctl/main.c
+++ b/drivers/fwctl/main.c
@@ -275,6 +275,8 @@ static void fwctl_device_release(struct device *device)

ida_free(&fwctl_ida, fwctl->dev.devt - fwctl_dev);
mutex_destroy(&fwctl->uctx_list_lock);
+ if (fwctl->release_data)
+ fwctl->release_data(fwctl);
kfree(fwctl);
}

diff --git a/include/linux/fwctl.h b/include/linux/fwctl.h
index 5d61fc8a6871..25834f6b79a8 100644
--- a/include/linux/fwctl.h
+++ b/include/linux/fwctl.h
@@ -79,6 +79,8 @@ struct fwctl_device {
*/
struct rw_semaphore registration_lock;
const struct fwctl_ops *ops;
+ /* Optional release hook for driver-private tail data. */
+ void (*release_data)(struct fwctl_device *fwctl);
};

struct fwctl_device *_fwctl_alloc_device(struct device *parent,
--
2.51.0