Skip to content

Commit

Permalink
file: remove __receive_fd()
Browse files Browse the repository at this point in the history
Honestly, there's little value in having a helper with and without that
int __user *ufd argument. It's just messy and doesn't really give us
anything. Just expose receive_fd() with that argument and get rid of
that helper.

Link: https://lore.kernel.org/r/[email protected]
Reviewed-by: Jan Kara <[email protected]>
Reviewed-by: Jens Axboe <[email protected]>
Signed-off-by: Christian Brauner <[email protected]>
  • Loading branch information
brauner committed Dec 12, 2023
1 parent eac9189 commit 4e94ddf
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion drivers/vdpa/vdpa_user/vduse_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd,
fput(f);
break;
}
ret = receive_fd(f, perm_to_file_flags(entry.perm));
ret = receive_fd(f, NULL, perm_to_file_flags(entry.perm));
fput(f);
break;
}
Expand Down
11 changes: 3 additions & 8 deletions fs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
}

/**
* __receive_fd() - Install received file into file descriptor table
* receive_fd() - Install received file into file descriptor table
* @file: struct file that was received from another process
* @ufd: __user pointer to write new fd number to
* @o_flags: the O_* flags to apply to the new fd entry
Expand All @@ -1310,7 +1310,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
*
* Returns newly install fd or -ve on error.
*/
int __receive_fd(struct file *file, int __user *ufd, unsigned int o_flags)
int receive_fd(struct file *file, int __user *ufd, unsigned int o_flags)
{
int new_fd;
int error;
Expand All @@ -1335,6 +1335,7 @@ int __receive_fd(struct file *file, int __user *ufd, unsigned int o_flags)
__receive_sock(file);
return new_fd;
}
EXPORT_SYMBOL_GPL(receive_fd);

int receive_fd_replace(int new_fd, struct file *file, unsigned int o_flags)
{
Expand All @@ -1350,12 +1351,6 @@ int receive_fd_replace(int new_fd, struct file *file, unsigned int o_flags)
return new_fd;
}

int receive_fd(struct file *file, unsigned int o_flags)
{
return __receive_fd(file, NULL, o_flags);
}
EXPORT_SYMBOL_GPL(receive_fd);

static int ksys_dup3(unsigned int oldfd, unsigned int newfd, int flags)
{
int err = -EBADF;
Expand Down
5 changes: 1 addition & 4 deletions include/linux/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ DEFINE_CLASS(get_unused_fd, int, if (_T >= 0) put_unused_fd(_T),

extern void fd_install(unsigned int fd, struct file *file);

extern int __receive_fd(struct file *file, int __user *ufd,
unsigned int o_flags);

extern int receive_fd(struct file *file, unsigned int o_flags);
int receive_fd(struct file *file, int __user *ufd, unsigned int o_flags);

int receive_fd_replace(int new_fd, struct file *file, unsigned int o_flags);

Expand Down
2 changes: 1 addition & 1 deletion include/net/scm.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static inline int scm_recv_one_fd(struct file *f, int __user *ufd,
{
if (!ufd)
return -EFAULT;
return __receive_fd(f, ufd, flags);
return receive_fd(f, ufd, flags);
}

#endif /* __LINUX_NET_SCM_H */
Expand Down
2 changes: 1 addition & 1 deletion kernel/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ static int pidfd_getfd(struct pid *pid, int fd)
if (IS_ERR(file))
return PTR_ERR(file);

ret = receive_fd(file, O_CLOEXEC);
ret = receive_fd(file, NULL, O_CLOEXEC);
fput(file);

return ret;
Expand Down
2 changes: 1 addition & 1 deletion kernel/seccomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ static void seccomp_handle_addfd(struct seccomp_kaddfd *addfd, struct seccomp_kn
*/
list_del_init(&addfd->list);
if (!addfd->setfd)
fd = receive_fd(addfd->file, addfd->flags);
fd = receive_fd(addfd->file, NULL, addfd->flags);
else
fd = receive_fd_replace(addfd->fd, addfd->file, addfd->flags);
addfd->ret = fd;
Expand Down

0 comments on commit 4e94ddf

Please sign in to comment.