]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
timerfd: convert timerfd_create() to FD_ADD()
authorChristian Brauner <brauner@kernel.org>
Sun, 23 Nov 2025 16:33:33 +0000 (17:33 +0100)
committerChristian Brauner <brauner@kernel.org>
Fri, 28 Nov 2025 11:42:32 +0000 (12:42 +0100)
Link: https://patch.msgid.link/20251123-work-fd-prepare-v4-15-b6efa1706cfd@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/timerfd.c

index c68f28d9c426f4ec21957b951ec621161e472ca7..9fcea7860ddf3e0a4328458b64b5f5f2dd0c7326 100644 (file)
@@ -393,9 +393,8 @@ static const struct file_operations timerfd_fops = {
 
 SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags)
 {
-       int ufd;
-       struct timerfd_ctx *ctx;
-       struct file *file;
+       struct timerfd_ctx *ctx __free(kfree) = NULL;
+       int ret;
 
        /* Check the TFD_* constants for consistency.  */
        BUILD_BUG_ON(TFD_CLOEXEC != O_CLOEXEC);
@@ -432,23 +431,13 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags)
 
        ctx->moffs = ktime_mono_to_real(0);
 
-       ufd = get_unused_fd_flags(flags & TFD_SHARED_FCNTL_FLAGS);
-       if (ufd < 0) {
-               kfree(ctx);
-               return ufd;
-       }
-
-       file = anon_inode_getfile_fmode("[timerfd]", &timerfd_fops, ctx,
-                           O_RDWR | (flags & TFD_SHARED_FCNTL_FLAGS),
-                           FMODE_NOWAIT);
-       if (IS_ERR(file)) {
-               put_unused_fd(ufd);
-               kfree(ctx);
-               return PTR_ERR(file);
-       }
-
-       fd_install(ufd, file);
-       return ufd;
+       ret = FD_ADD(flags & TFD_SHARED_FCNTL_FLAGS,
+                    anon_inode_getfile_fmode("[timerfd]", &timerfd_fops, ctx,
+                                             O_RDWR | (flags & TFD_SHARED_FCNTL_FLAGS),
+                                             FMODE_NOWAIT));
+       if (ret >= 0)
+               retain_and_null_ptr(ctx);
+       return ret;
 }
 
 static int do_timerfd_settime(int ufd, int flags,