[PATCH 07/12] eventfd: use __anon_inode_getfd

From: Christoph Hellwig
Date: Fri May 08 2020 - 11:37:04 EST


Use __anon_inode_getfd instead of opencoding the logic using
get_unused_fd_flags + anon_inode_getfile.

Signed-off-by: Christoph Hellwig <hch@xxxxxx>
---
fs/eventfd.c | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/fs/eventfd.c b/fs/eventfd.c
index df466ef81dddf..9b6d5137679b2 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -423,20 +423,11 @@ static int do_eventfd(unsigned int count, int flags)
ctx->count = count;
ctx->flags = flags;
ctx->id = ida_simple_get(&eventfd_ida, 0, 0, GFP_KERNEL);
-
- flags &= EFD_SHARED_FCNTL_FLAGS;
- flags |= O_RDWR;
- fd = get_unused_fd_flags(flags);
+ fd = __anon_inode_getfd("[eventfd]", &eventfd_fops, ctx,
+ (flags & EFD_SHARED_FCNTL_FLAGS) | O_RDWR, &file);
if (fd < 0)
goto err;

- file = anon_inode_getfile("[eventfd]", &eventfd_fops, ctx, flags);
- if (IS_ERR(file)) {
- put_unused_fd(fd);
- fd = PTR_ERR(file);
- goto err;
- }
-
file->f_mode |= FMODE_NOWAIT;
fd_install(fd, file);
return fd;
--
2.26.2