diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2022-05-12 23:08:03 +0200 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2022-05-15 00:49:01 +0200 |
commit | 6319194ec57b0452dcda4589d24c4e7db299c5bf (patch) | |
tree | d65162000bc0031c8e5946aa7135c9dad7496d6c /fs/io_uring.c | |
parent | fs: remove fget_many and fput_many interface (diff) | |
download | linux-6319194ec57b0452dcda4589d24c4e7db299c5bf.tar.xz linux-6319194ec57b0452dcda4589d24c4e7db299c5bf.zip |
Unify the primitives for file descriptor closing
Currently we have 3 primitives for removing an opened file from descriptor
table - pick_file(), __close_fd_get_file() and close_fd_get_file(). Their
calling conventions are rather odd and there's a code duplication for no
good reason. They can be unified -
1) have __range_close() cap max_fd in the very beginning; that way
we don't need separate way for pick_file() to report being past the end
of descriptor table.
2) make {__,}close_fd_get_file() return file (or NULL) directly, rather
than returning it via struct file ** argument. Don't bother with
(bogus) return value - nobody wants that -ENOENT.
3) make pick_file() return NULL on unopened descriptor - the only caller
that used to care about the distinction between descriptor past the end
of descriptor table and finding NULL in descriptor table doesn't give
a damn after (1).
4) lift ->files_lock out of pick_file()
That actually simplifies the callers, as well as the primitives themselves.
Code duplication is also gone...
Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/io_uring.c')
-rw-r--r-- | fs/io_uring.c | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c index dc580a30723d..7257b0870353 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -5137,13 +5137,10 @@ static int io_close(struct io_kiocb *req, unsigned int issue_flags) return -EAGAIN; } - ret = __close_fd_get_file(close->fd, &file); + file = __close_fd_get_file(close->fd); spin_unlock(&files->file_lock); - if (ret < 0) { - if (ret == -ENOENT) - ret = -EBADF; + if (!file) goto err; - } /* No ->flush() or already async, safely close from here */ ret = filp_close(file, current->files); |