diff options
author | Pavel Begunkov <asml.silence@gmail.com> | 2021-04-11 01:46:36 +0100 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2021-04-12 09:32:58 -0600 |
commit | 87094465d01a248cd888b81da0e6bc10324d4dc0 (patch) | |
tree | 006814e726070f5fe04f102d328cfdd24c574b05 /fs/io_uring.c | |
parent | 7f61a1e9ef511660d66ea926b5899559fe94b1d0 (diff) | |
download | lwn-87094465d01a248cd888b81da0e6bc10324d4dc0.tar.gz lwn-87094465d01a248cd888b81da0e6bc10324d4dc0.zip |
io_uring: cleanup buffer register
In preparation for more changes do a little cleanup of
io_sqe_buffers_register(). Move all args/invariant checking into it from
io_buffers_map_alloc(), because it's confusing. And add a bit more
cleaning for the loop.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/93292cb9708c8455e5070cc855861d94e11ca042.1618101759.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.c | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c index e9a2f8f39eb3..76c8bd6a25d1 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -8306,17 +8306,8 @@ done: static int io_buffers_map_alloc(struct io_ring_ctx *ctx, unsigned int nr_args) { - if (ctx->user_bufs) - return -EBUSY; - if (!nr_args || nr_args > UIO_MAXIOV) - return -EINVAL; - - ctx->user_bufs = kcalloc(nr_args, sizeof(struct io_mapped_ubuf), - GFP_KERNEL); - if (!ctx->user_bufs) - return -ENOMEM; - - return 0; + ctx->user_bufs = kcalloc(nr_args, sizeof(*ctx->user_bufs), GFP_KERNEL); + return ctx->user_bufs ? 0 : -ENOMEM; } static int io_buffer_validate(struct iovec *iov) @@ -8348,26 +8339,26 @@ static int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg, struct iovec iov; struct page *last_hpage = NULL; + if (ctx->user_bufs) + return -EBUSY; + if (!nr_args || nr_args > UIO_MAXIOV) + return -EINVAL; ret = io_buffers_map_alloc(ctx, nr_args); if (ret) return ret; - for (i = 0; i < nr_args; i++) { + for (i = 0; i < nr_args; i++, ctx->nr_user_bufs++) { struct io_mapped_ubuf *imu = &ctx->user_bufs[i]; ret = io_copy_iov(ctx, &iov, arg, i); if (ret) break; - ret = io_buffer_validate(&iov); if (ret) break; - ret = io_sqe_buffer_register(ctx, &iov, imu, &last_hpage); if (ret) break; - - ctx->nr_user_bufs++; } if (ret) |