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

Signed-off-by: Bence Csokas <[email protected]>
---
 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..1cd1741b81b1 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 (IS_ERR_OR_NULL(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

Reply via email to