From: Jeff Layton <jlayton@kernel.org>
To: Christian Brauner <brauner@kernel.org>, Oleg Nesterov <oleg@redhat.com>
Cc: linux-fsdevel@vger.kernel.org,
Lennart Poettering <lennart@poettering.net>,
Daan De Meyer <daan.j.demeyer@gmail.com>,
Mike Yuan <me@yhndnzj.com>
Subject: Re: [PATCH v2 02/15] pidfd: rely on automatic cleanup in __pidfd_prepare()
Date: Tue, 04 Mar 2025 07:44:29 -0500 [thread overview]
Message-ID: <1a890668d631b127e3b58d096cee62edb5a27176.camel@kernel.org> (raw)
In-Reply-To: <20250304-work-pidfs-kill_on_last_close-v2-2-44fdacfaa7b7@kernel.org>
On Tue, 2025-03-04 at 10:41 +0100, Christian Brauner wrote:
> Rely on scope-based cleanup for the allocated file descriptor.
>
> Signed-off-by: Christian Brauner <brauner@kernel.org>
> ---
> kernel/fork.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 735405a9c5f3..6230f5256bc5 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -2032,25 +2032,23 @@ static inline void rcu_copy_process(struct task_struct *p)
> */
> static int __pidfd_prepare(struct pid *pid, unsigned int flags, struct file **ret)
> {
> - int pidfd;
> struct file *pidfd_file;
>
> - pidfd = get_unused_fd_flags(O_CLOEXEC);
> + CLASS(get_unused_fd, pidfd)(O_CLOEXEC);
> if (pidfd < 0)
> return pidfd;
>
> pidfd_file = pidfs_alloc_file(pid, flags | O_RDWR);
> - if (IS_ERR(pidfd_file)) {
> - put_unused_fd(pidfd);
> + if (IS_ERR(pidfd_file))
> return PTR_ERR(pidfd_file);
> - }
> +
> /*
> * anon_inode_getfile() ignores everything outside of the
> * O_ACCMODE | O_NONBLOCK mask, set PIDFD_THREAD manually.
> */
> pidfd_file->f_flags |= (flags & PIDFD_THREAD);
> *ret = pidfd_file;
> - return pidfd;
> + return take_fd(pidfd);
> }
>
> /**
>
I'll Ack this, but I will say that I find the result to be less
readable than what was there before.
Acked-by: Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2025-03-04 12:44 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-04 9:41 [PATCH v2 00/15] pidfs: provide information after task has been reaped Christian Brauner
2025-03-04 9:41 ` [PATCH v2 01/15] pidfs: switch to copy_struct_to_user() Christian Brauner
2025-03-04 12:42 ` Jeff Layton
2025-03-04 9:41 ` [PATCH v2 02/15] pidfd: rely on automatic cleanup in __pidfd_prepare() Christian Brauner
2025-03-04 12:44 ` Jeff Layton [this message]
2025-03-04 9:41 ` [PATCH v2 03/15] pidfs: move setting flags into pidfs_alloc_file() Christian Brauner
2025-03-04 12:53 ` Jeff Layton
2025-03-04 9:41 ` [PATCH v2 04/15] pidfs: add inode allocation Christian Brauner
2025-03-04 13:06 ` Jeff Layton
2025-03-04 9:41 ` [PATCH v2 05/15] pidfs: record exit code and cgroupid at exit Christian Brauner
2025-03-04 13:05 ` Jeff Layton
2025-03-04 13:10 ` Oleg Nesterov
2025-03-04 19:10 ` Christian Brauner
2025-03-04 9:41 ` [PATCH v2 06/15] pidfs: allow to retrieve exit information Christian Brauner
2025-03-04 13:27 ` Jeff Layton
2025-03-04 17:23 ` Christian Brauner
2025-03-04 17:22 ` Oleg Nesterov
2025-03-04 20:16 ` Christian Brauner
2025-03-04 17:34 ` Oleg Nesterov
2025-03-04 20:09 ` Christian Brauner
2025-03-04 21:47 ` Oleg Nesterov
2025-03-05 8:54 ` Christian Brauner
2025-03-04 9:41 ` [PATCH v2 07/15] selftests/pidfd: fix header inclusion Christian Brauner
2025-03-04 9:41 ` [PATCH v2 08/15] pidfs/selftests: ensure correct headers for ioctl handling Christian Brauner
2025-03-04 9:41 ` [PATCH v2 09/15] selftests/pidfd: move more defines to common header Christian Brauner
2025-03-04 9:41 ` [PATCH v2 10/15] selftests/pidfd: add first PIDFD_INFO_EXIT selftest Christian Brauner
2025-03-04 9:41 ` [PATCH v2 11/15] selftests/pidfd: add second " Christian Brauner
2025-03-04 9:41 ` [PATCH v2 12/15] selftests/pidfd: add third " Christian Brauner
2025-03-04 9:41 ` [PATCH v2 13/15] selftests/pidfd: add fourth " Christian Brauner
2025-03-04 9:41 ` [PATCH v2 14/15] selftests/pidfd: add fifth " Christian Brauner
2025-03-04 9:41 ` [PATCH v2 15/15] selftests/pidfd: add sixth " Christian Brauner
2025-03-04 20:18 ` [PATCH v2 17/16] selftests/pidfd: test multi-threaded exec with PPIDFD_INFO_EXIT 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=1a890668d631b127e3b58d096cee62edb5a27176.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=brauner@kernel.org \
--cc=daan.j.demeyer@gmail.com \
--cc=lennart@poettering.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=me@yhndnzj.com \
--cc=oleg@redhat.com \
/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