summaryrefslogtreecommitdiff
path: root/fs/io_uring.c
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2021-04-01 15:43:42 +0100
committerJens Axboe <axboe@kernel.dk>2021-04-11 19:30:34 -0600
commitf3baed39929edc5fa0ce7a897567153c87551776 (patch)
tree235c1101451ce9e9749def777ede7c986b065efe /fs/io_uring.c
parent221aa92409f945a19ce28c5cb54b4d9957f90715 (diff)
downloadlwn-f3baed39929edc5fa0ce7a897567153c87551776.tar.gz
lwn-f3baed39929edc5fa0ce7a897567153c87551776.zip
io_uring: use rsrc prealloc infra for files reg
Keep it consistent with update and use io_rsrc_node_prealloc() + io_rsrc_node_get() in io_sqe_files_register() as well, that will be used in future patches, not as error prone and allows to deduplicate rsrc_node init. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/cf87321e6be5e38f4dc7fe5079d2aa6945b1ace0.1617287883.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'fs/io_uring.c')
-rw-r--r--fs/io_uring.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c
index ed7685caa8f8..8b4394f1285d 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7623,13 +7623,6 @@ static struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx)
return ref_node;
}
-static void init_fixed_file_ref_node(struct io_ring_ctx *ctx,
- struct io_rsrc_node *ref_node)
-{
- ref_node->rsrc_data = ctx->file_data;
- ref_node->rsrc_put = io_ring_file_put;
-}
-
static void io_rsrc_node_destroy(struct io_rsrc_node *ref_node)
{
percpu_ref_exit(&ref_node->refs);
@@ -7642,7 +7635,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
__s32 __user *fds = (__s32 __user *) arg;
unsigned nr_tables, i;
struct file *file;
- int fd, ret = -ENOMEM;
+ int fd, ret;
struct io_rsrc_node *ref_node;
struct io_rsrc_data *file_data;
@@ -7652,12 +7645,16 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
return -EINVAL;
if (nr_args > IORING_MAX_FIXED_FILES)
return -EMFILE;
+ ret = io_rsrc_node_prealloc(ctx);
+ if (ret)
+ return ret;
file_data = io_rsrc_data_alloc(ctx);
if (!file_data)
return -ENOMEM;
ctx->file_data = file_data;
+ ret = -ENOMEM;
nr_tables = DIV_ROUND_UP(nr_args, IORING_MAX_FILES_TABLE);
file_data->table = kcalloc(nr_tables, sizeof(*file_data->table),
GFP_KERNEL);
@@ -7710,13 +7707,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
return ret;
}
- ref_node = io_rsrc_node_alloc(ctx);
- if (!ref_node) {
- io_sqe_files_unregister(ctx);
- return -ENOMEM;
- }
- init_fixed_file_ref_node(ctx, ref_node);
-
+ ref_node = io_rsrc_node_get(ctx, ctx->file_data, io_ring_file_put);
io_rsrc_node_set(ctx, file_data, ref_node);
return ret;
out_fput: