Re: [PATCH v2 02/15] pidfd: rely on automatic cleanup in __pidfd_prepare()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> ---
>  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@xxxxxxxxxx>





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux