mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] Add scope-based cleanup capability to eventfd_ctx
@ 2026-09-09 12:36 Bence Csokas
  2026-09-09 12:36 ` [PATCH 1/2] eventfd: Add scope-based cleanup capability Bence Csokas
  2026-09-09 12:36 ` [PATCH 2/2] drm/syncobj: Use scope-based cleanup for eventfd_ctx Bence Csokas
  0 siblings, 2 replies; 3+ messages in thread
From: Bence Csokas @ 2026-09-09 12:36 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Jan Kara, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter
  Cc: linux-fsdevel, linux-kernel, dri-devel, Bence Csokas

Add __free() support to eventfd and update drm_syncobj to use it as an
example consumer.

A minor discrepancy I encountered is whether to put a semicolon after
DEFINE_FREE(). It seems some in-tree code does, some doesn't. In the end,
I followed the example set in core-api/cleanup.rst, and omitted it.

Signed-off-by: Bence Csokas <bence.csokas@arm.com>
---
Bence Csokas (2):
      eventfd: Add scope-based cleanup capability
      drm/syncobj: Use scope-based cleanup for eventfd_ctx

 drivers/gpu/drm/drm_syncobj.c | 9 ++++-----
 fs/eventfd.c                  | 3 +++
 include/linux/eventfd.h       | 3 +++
 3 files changed, 10 insertions(+), 5 deletions(-)
---
base-commit: 893e11787f78e43b534e252249ac3fff4d1333f8
change-id: 20260826-efd-autofree-766608e8d8aa

Best regards,
--  
Bence Csokas <bence.csokas@arm.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] eventfd: Add scope-based cleanup capability
  2026-09-09 12:36 [PATCH 0/2] Add scope-based cleanup capability to eventfd_ctx Bence Csokas
@ 2026-09-09 12:36 ` Bence Csokas
  2026-09-09 12:36 ` [PATCH 2/2] drm/syncobj: Use scope-based cleanup for eventfd_ctx Bence Csokas
  1 sibling, 0 replies; 3+ messages in thread
From: Bence Csokas @ 2026-09-09 12:36 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Jan Kara, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter
  Cc: linux-fsdevel, linux-kernel, dri-devel, Bence Csokas

Allow eventfd_ctx_put() to be used with the RAII-inspired __free() API.

Signed-off-by: Bence Csokas <bence.csokas@arm.com>
---
 fs/eventfd.c            | 3 +++
 include/linux/eventfd.h | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/fs/eventfd.c b/fs/eventfd.c
index 9d33a02757d5..24111a16284f 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -102,6 +102,9 @@ static void eventfd_free(struct kref *kref)
  */
 void eventfd_ctx_put(struct eventfd_ctx *ctx)
 {
+	if (!ctx)
+		return;
+
 	kref_put(&ctx->kref, eventfd_free);
 }
 EXPORT_SYMBOL_GPL(eventfd_ctx_put);
diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
index e32bee4345fb..689358c2b0ae 100644
--- a/include/linux/eventfd.h
+++ b/include/linux/eventfd.h
@@ -10,6 +10,7 @@
 #define _LINUX_EVENTFD_H
 
 #include <linux/wait.h>
+#include <linux/cleanup.h>
 #include <linux/err.h>
 #include <linux/percpu-defs.h>
 #include <linux/percpu.h>
@@ -89,5 +90,7 @@ static inline void eventfd_signal(struct eventfd_ctx *ctx)
 	eventfd_signal_mask(ctx, 0);
 }
 
+DEFINE_FREE(eventfd, struct eventfd_ctx *, eventfd_ctx_put(_T))
+
 #endif /* _LINUX_EVENTFD_H */
 

-- 
2.55.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] drm/syncobj: Use scope-based cleanup for eventfd_ctx
  2026-09-09 12:36 [PATCH 0/2] Add scope-based cleanup capability to eventfd_ctx Bence Csokas
  2026-09-09 12:36 ` [PATCH 1/2] eventfd: Add scope-based cleanup capability Bence Csokas
@ 2026-09-09 12:36 ` Bence Csokas
  1 sibling, 0 replies; 3+ messages in thread
From: Bence Csokas @ 2026-09-09 12:36 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Jan Kara, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter
  Cc: linux-fsdevel, linux-kernel, dri-devel, Bence Csokas

Now that eventfd supports __free(), use it in drm_syncobj_eventfd_ioctl().

Signed-off-by: Bence Csokas <bence.csokas@arm.com>
---
 drivers/gpu/drm/drm_syncobj.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index c23a5de27eff..261d5606e8bd 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -1462,9 +1462,9 @@ int
 drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data,
 			  struct drm_file *file_private)
 {
+	struct eventfd_ctx *ev_fd_ctx __free(eventfd) = NULL;
 	struct drm_syncobj_eventfd *args = data;
 	struct drm_syncobj *syncobj;
-	struct eventfd_ctx *ev_fd_ctx;
 	struct syncobj_eventfd_entry *entry;
 	int ret;
 
@@ -1484,16 +1484,17 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data,
 	ev_fd_ctx = eventfd_ctx_fdget(args->fd);
 	if (IS_ERR(ev_fd_ctx)) {
 		ret = PTR_ERR(ev_fd_ctx);
+		ev_fd_ctx = NULL;
 		goto err_fdget;
 	}
 
 	entry = kzalloc_obj(*entry);
 	if (!entry) {
 		ret = -ENOMEM;
-		goto err_kzalloc;
+		goto err_fdget;
 	}
 	entry->syncobj = syncobj;
-	entry->ev_fd_ctx = ev_fd_ctx;
+	entry->ev_fd_ctx = no_free_ptr(ev_fd_ctx);
 	entry->point = args->point;
 	entry->flags = args->flags;
 
@@ -1502,8 +1503,6 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data,
 
 	return 0;
 
-err_kzalloc:
-	eventfd_ctx_put(ev_fd_ctx);
 err_fdget:
 	drm_syncobj_put(syncobj);
 	return ret;

-- 
2.55.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-09 12:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-09 12:36 [PATCH 0/2] Add scope-based cleanup capability to eventfd_ctx Bence Csokas
2026-09-09 12:36 ` [PATCH 1/2] eventfd: Add scope-based cleanup capability Bence Csokas
2026-09-09 12:36 ` [PATCH 2/2] drm/syncobj: Use scope-based cleanup for eventfd_ctx Bence Csokas

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®