linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
	 linux-fsdevel@vger.kernel.org,
	Christian Brauner <brauner@kernel.org>
Subject: [PATCH DRAFT RFC UNTESTED 15/18] fs: timerfd
Date: Tue, 18 Nov 2025 16:48:55 +0100	[thread overview]
Message-ID: <20251118-work-fd-prepare-v1-15-c20504d97375@kernel.org> (raw)
In-Reply-To: <20251118-work-fd-prepare-v1-0-c20504d97375@kernel.org>

Placeholder commit message.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/timerfd.c | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/fs/timerfd.c b/fs/timerfd.c
index c68f28d9c426..acaad0a086b1 100644
--- a/fs/timerfd.c
+++ b/fs/timerfd.c
@@ -393,9 +393,7 @@ 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;
 
 	/* Check the TFD_* constants for consistency.  */
 	BUILD_BUG_ON(TFD_CLOEXEC != O_CLOEXEC);
@@ -432,23 +430,15 @@ 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_PREPARE(fdprep, flags & TFD_SHARED_FCNTL_FLAGS,
+		   anon_inode_getfile_fmode("[timerfd]", &timerfd_fops, ctx,
+					    O_RDWR | (flags & TFD_SHARED_FCNTL_FLAGS),
+					    FMODE_NOWAIT));
+	if (fd_prepare_failed(fdprep))
+		return fd_prepare_error(fdprep);
 
-	fd_install(ufd, file);
-	return ufd;
+	retain_and_null_ptr(ctx);
+	return fd_publish(fdprep);
 }
 
 static int do_timerfd_settime(int ufd, int flags, 

-- 
2.47.3


  parent reply	other threads:[~2025-11-18 15:50 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-18 15:48 [PATCH DRAFT RFC UNTESTED 00/18] file: FD_PREPARE() Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 01/18] file: add FD_PREPARE() Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 02/18] fs: anon_inodes Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 03/18] fs: eventfd Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 04/18] fs: fhandle Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 05/18] fs: open_tree() Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 06/18] fs: namespace Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 07/18] fs: fanotify Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 08/18] fs: nsfs Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 09/18] fs: autofs Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 10/18] fs: eventpoll Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 11/18] fs: open_tree_attr() Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 12/18] fs: nsfs2 Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 13/18] fs: open Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 14/18] fs: signalfd64 Christian Brauner
2025-11-18 15:48 ` Christian Brauner [this message]
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 16/18] fs: userfaultfd Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 17/18] fs: xfs Christian Brauner
2025-11-18 15:48 ` [PATCH DRAFT RFC UNTESTED 18/18] drivers: drm_lease Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251118-work-fd-prepare-v1-15-c20504d97375@kernel.org \
    --to=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).