file: Rename __close_fd to close_fd and remove the files parameter

ANBZ: #9824

commit 8760c909f5 upstream.

The function __close_fd was added to support binder[1].  Now that
binder has been fixed to no longer need __close_fd[2] all calls
to __close_fd pass current->files.

Therefore transform the files parameter into a local variable
initialized to current->files, and rename __close_fd to close_fd to
reflect this change, and keep it in sync with the similar changes to
__alloc_fd, and __fd_install.

This removes the need for callers to care about the extra care that
needs to be take if anything except current->files is passed, by
limiting the callers to only operation on current->files.

[Fix conflict]
1. fs/cachefiles/ondemand.c used __close_fd, change it to close_fd.
2. We can't delete __close_fd because it might be used by OOT modules,
kABI force this reserved.

[1] 483ce1d4b8 ("take descriptor-related part of close() to file.c")
[2] 44d8047f1d ("binder: use standard functions to allocate fds")
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
v1: https://lkml.kernel.org/r/20200817220425.9389-17-ebiederm@xmission.com
Link: https://lkml.kernel.org/r/20201120231441.29911-21-ebiederm@xmission.com
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Ferry Meng <mengferry@linux.alibaba.com>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Link: https://gitee.com/anolis/cloud-kernel/pulls/3779
This commit is contained in:
Eric W. Biederman 2020-11-20 17:14:38 -06:00 committed by 小龙
parent 6d23ead410
commit 5d03225f15
5 changed files with 13 additions and 7 deletions

View File

@ -380,8 +380,7 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
err_put_fd:
if (msg->opcode == CACHEFILES_OP_OPEN)
__close_fd(current->files,
((struct cachefiles_open *)msg->data)->fd);
close_fd(((struct cachefiles_open *)msg->data)->fd);
error:
xa_lock(&cache->reqs);
radix_tree_delete(&cache->reqs, id);

View File

@ -674,6 +674,12 @@ int __close_fd(struct files_struct *files, unsigned fd)
}
EXPORT_SYMBOL(__close_fd); /* for ksys_close() */
int close_fd(unsigned fd)
{
return __close_fd(current->files, fd);
}
EXPORT_SYMBOL(close_fd); /* for ksys_close() */
/**
* __close_range() - Close all file descriptors in a given range.
*
@ -1087,7 +1093,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
struct files_struct *files = current->files;
if (!file)
return __close_fd(files, fd);
return close_fd(fd);
if (fd >= rlimit(RLIMIT_NOFILE))
return -EBADF;

View File

@ -1358,7 +1358,7 @@ EXPORT_SYMBOL(filp_close);
*/
SYSCALL_DEFINE1(close, unsigned int, fd)
{
int retval = __close_fd(current->files, fd);
int retval = close_fd(fd);
/* can't restart close syscall because file table entry was cleared */
if (unlikely(retval == -ERESTARTSYS ||

View File

@ -126,6 +126,7 @@ int iterate_fd(struct files_struct *, unsigned,
extern int __close_fd(struct files_struct *files,
unsigned int fd);
extern int close_fd(unsigned int fd);
extern int __close_range(unsigned int fd, unsigned int max_fd, unsigned int flags);
extern int close_fd_get_file(unsigned int fd, struct file **res);
extern int unshare_fd(unsigned long unshare_flags, unsigned int max_fds,

View File

@ -1325,16 +1325,16 @@ static inline long ksys_ftruncate(unsigned int fd, loff_t length)
return do_sys_ftruncate(fd, length, 1);
}
extern int __close_fd(struct files_struct *files, unsigned int fd);
extern int close_fd(unsigned int fd);
/*
* In contrast to sys_close(), this stub does not check whether the syscall
* should or should not be restarted, but returns the raw error codes from
* __close_fd().
* close_fd().
*/
static inline int ksys_close(unsigned int fd)
{
return __close_fd(current->files, fd);
return close_fd(fd);
}
extern long do_sys_truncate(const char __user *pathname, loff_t length);