Skip to content

Commit

Permalink
file: Rename __close_fd to close_fd and remove the files parameter
Browse files Browse the repository at this point in the history
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.

[1] 483ce1d ("take descriptor-related part of close() to file.c")
[2] 44d8047 ("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>
  • Loading branch information
Eric W. Biederman committed Dec 10, 2020
1 parent aa384d1 commit 8760c90
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
10 changes: 4 additions & 6 deletions fs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,9 @@ static struct file *pick_file(struct files_struct *files, unsigned fd)
return file;
}

/*
* The same warnings as for __alloc_fd()/__fd_install() apply here...
*/
int __close_fd(struct files_struct *files, unsigned fd)
int close_fd(unsigned fd)
{
struct files_struct *files = current->files;
struct file *file;

file = pick_file(files, fd);
Expand All @@ -642,7 +640,7 @@ int __close_fd(struct files_struct *files, unsigned fd)

return filp_close(file, files);
}
EXPORT_SYMBOL(__close_fd); /* for ksys_close() */
EXPORT_SYMBOL(close_fd); /* for ksys_close() */

/**
* __close_range() - Close all file descriptors in a given range.
Expand Down Expand Up @@ -1027,7 +1025,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;
Expand Down
2 changes: 1 addition & 1 deletion fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,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 ||
Expand Down
3 changes: 1 addition & 2 deletions include/linux/fdtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ int iterate_fd(struct files_struct *, unsigned,
int (*)(const void *, struct file *, unsigned),
const void *);

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,
Expand Down
6 changes: 3 additions & 3 deletions include/linux/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -1295,16 +1295,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);
Expand Down

0 comments on commit 8760c90

Please sign in to comment.