Skip to content

Commit 24fa3ae

Browse files
committed
file: remove pointless wrapper
Only io_uring uses __close_fd_get_file(). All it does is hide current->files but io_uring accesses files_struct directly right now anyway so it's a bit pointless. Just rename pick_file() to file_close_fd_locked() and let io_uring use it. Add a lockdep assert in there that we expect the caller to hold file_lock while we're at it. Link: https://lore.kernel.org/r/20231130-vfs-files-fixes-v1-2-e73ca6f4ea83@kernel.org Reviewed-by: Jens Axboe <axboe@kernel.dk> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent a88c955 commit 24fa3ae

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

fs/file.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -629,19 +629,23 @@ void fd_install(unsigned int fd, struct file *file)
629629
EXPORT_SYMBOL(fd_install);
630630

631631
/**
632-
* pick_file - return file associatd with fd
632+
* file_close_fd_locked - return file associated with fd
633633
* @files: file struct to retrieve file from
634634
* @fd: file descriptor to retrieve file for
635635
*
636+
* Doesn't take a separate reference count.
637+
*
636638
* Context: files_lock must be held.
637639
*
638640
* Returns: The file associated with @fd (NULL if @fd is not open)
639641
*/
640-
static struct file *pick_file(struct files_struct *files, unsigned fd)
642+
struct file *file_close_fd_locked(struct files_struct *files, unsigned fd)
641643
{
642644
struct fdtable *fdt = files_fdtable(files);
643645
struct file *file;
644646

647+
lockdep_assert_held(&files->file_lock);
648+
645649
if (fd >= fdt->max_fds)
646650
return NULL;
647651

@@ -660,7 +664,7 @@ int close_fd(unsigned fd)
660664
struct file *file;
661665

662666
spin_lock(&files->file_lock);
663-
file = pick_file(files, fd);
667+
file = file_close_fd_locked(files, fd);
664668
spin_unlock(&files->file_lock);
665669
if (!file)
666670
return -EBADF;
@@ -707,7 +711,7 @@ static inline void __range_close(struct files_struct *files, unsigned int fd,
707711
max_fd = min(max_fd, n);
708712

709713
for (; fd <= max_fd; fd++) {
710-
file = pick_file(files, fd);
714+
file = file_close_fd_locked(files, fd);
711715
if (file) {
712716
spin_unlock(&files->file_lock);
713717
filp_close(file, files);
@@ -795,15 +799,6 @@ int __close_range(unsigned fd, unsigned max_fd, unsigned int flags)
795799
return 0;
796800
}
797801

798-
/*
799-
* See file_close_fd() below, this variant assumes current->files->file_lock
800-
* is held.
801-
*/
802-
struct file *__close_fd_get_file(unsigned int fd)
803-
{
804-
return pick_file(current->files, fd);
805-
}
806-
807802
/**
808803
* file_close_fd - return file associated with fd
809804
* @fd: file descriptor to retrieve file for
@@ -818,7 +813,7 @@ struct file *file_close_fd(unsigned int fd)
818813
struct file *file;
819814

820815
spin_lock(&files->file_lock);
821-
file = pick_file(files, fd);
816+
file = file_close_fd_locked(files, fd);
822817
spin_unlock(&files->file_lock);
823818

824819
return file;

fs/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ extern struct file *do_file_open_root(const struct path *,
179179
const char *, const struct open_flags *);
180180
extern struct open_how build_open_how(int flags, umode_t mode);
181181
extern int build_open_flags(const struct open_how *how, struct open_flags *op);
182-
extern struct file *__close_fd_get_file(unsigned int fd);
182+
struct file *file_close_fd_locked(struct files_struct *files, unsigned fd);
183183

184184
long do_sys_ftruncate(unsigned int fd, loff_t length, int small);
185185
int chmod_common(const struct path *path, umode_t mode);

io_uring/openclose.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ int io_close(struct io_kiocb *req, unsigned int issue_flags)
241241
return -EAGAIN;
242242
}
243243

244-
file = __close_fd_get_file(close->fd);
244+
file = file_close_fd_locked(files, close->fd);
245245
spin_unlock(&files->file_lock);
246246
if (!file)
247247
goto err;

0 commit comments

Comments
 (0)