mirror of
https://github.com/torvalds/linux.git
synced 2025-12-01 07:26:02 +07:00
pidfd: rely on automatic cleanup in __pidfd_prepare()
Rely on scope-based cleanup for the allocated file descriptor. Link: https://lore.kernel.org/r/20250305-work-pidfs-kill_on_last_close-v3-2-c8c3d8361705@kernel.org Acked-by: Jeff Layton <jlayton@kernel.org> Reviewed-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user