eventfd: convert do_eventfd() to FD_PREPARE()

Link: https://patch.msgid.link/20251123-work-fd-prepare-v4-3-b6efa1706cfd@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Christian Brauner 2025-11-23 17:33:21 +01:00
parent 8797dd5600
commit a5fa9ab846
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2
1 changed files with 10 additions and 19 deletions

View File

@ -378,9 +378,7 @@ EXPORT_SYMBOL_GPL(eventfd_ctx_fileget);
static int do_eventfd(unsigned int count, int flags) static int do_eventfd(unsigned int count, int flags)
{ {
struct eventfd_ctx *ctx; struct eventfd_ctx *ctx __free(kfree) = NULL;
struct file *file;
int fd;
/* Check the EFD_* constants for consistency. */ /* Check the EFD_* constants for consistency. */
BUILD_BUG_ON(EFD_CLOEXEC != O_CLOEXEC); BUILD_BUG_ON(EFD_CLOEXEC != O_CLOEXEC);
@ -398,26 +396,19 @@ static int do_eventfd(unsigned int count, int flags)
init_waitqueue_head(&ctx->wqh); init_waitqueue_head(&ctx->wqh);
ctx->count = count; ctx->count = count;
ctx->flags = flags; ctx->flags = flags;
ctx->id = ida_alloc(&eventfd_ida, GFP_KERNEL);
flags &= EFD_SHARED_FCNTL_FLAGS; flags &= EFD_SHARED_FCNTL_FLAGS;
flags |= O_RDWR; flags |= O_RDWR;
fd = get_unused_fd_flags(flags);
if (fd < 0)
goto err;
file = anon_inode_getfile_fmode("[eventfd]", &eventfd_fops, FD_PREPARE(fdf, flags,
ctx, flags, FMODE_NOWAIT); anon_inode_getfile_fmode("[eventfd]", &eventfd_fops, ctx,
if (IS_ERR(file)) { flags, FMODE_NOWAIT));
put_unused_fd(fd); if (fdf.err)
fd = PTR_ERR(file); return fdf.err;
goto err;
} ctx->id = ida_alloc(&eventfd_ida, GFP_KERNEL);
fd_install(fd, file); retain_and_null_ptr(ctx);
return fd; return fd_publish(fdf);
err:
eventfd_free_ctx(ctx);
return fd;
} }
SYSCALL_DEFINE2(eventfd2, unsigned int, count, int, flags) SYSCALL_DEFINE2(eventfd2, unsigned int, count, int, flags)