summaryrefslogtreecommitdiffstats
path: root/io_uring/io_uring.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2021-11-06 00:15:46 +0100
committerJens Axboe <axboe@kernel.dk>2023-05-16 16:04:49 +0200
commit9c189eee73af1825ea9c895fafad469de5f82641 (patch)
tree3e824b5d5aaee1fa30efa5b80ed5dfd8b6f5de51 /io_uring/io_uring.c
parentio_uring: return error pointer from io_mem_alloc() (diff)
downloadlinux-9c189eee73af1825ea9c895fafad469de5f82641.tar.xz
linux-9c189eee73af1825ea9c895fafad469de5f82641.zip
io_uring: add ring freeing helper
We do rings and sqes separately, move them into a helper that does both the freeing and clearing of the memory. Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'io_uring/io_uring.c')
-rw-r--r--io_uring/io_uring.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index aa4759e90a45..74433939a318 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2688,6 +2688,14 @@ static void io_mem_free(void *ptr)
free_compound_page(page);
}
+static void io_rings_free(struct io_ring_ctx *ctx)
+{
+ io_mem_free(ctx->rings);
+ io_mem_free(ctx->sq_sqes);
+ ctx->rings = NULL;
+ ctx->sq_sqes = NULL;
+}
+
static void *io_mem_alloc(size_t size)
{
gfp_t gfp = GFP_KERNEL_ACCOUNT | __GFP_ZERO | __GFP_NOWARN | __GFP_COMP;
@@ -2852,8 +2860,7 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
mmdrop(ctx->mm_account);
ctx->mm_account = NULL;
}
- io_mem_free(ctx->rings);
- io_mem_free(ctx->sq_sqes);
+ io_rings_free(ctx);
percpu_ref_exit(&ctx->refs);
free_uid(ctx->user);
@@ -3682,15 +3689,13 @@ static __cold int io_allocate_scq_urings(struct io_ring_ctx *ctx,
else
size = array_size(sizeof(struct io_uring_sqe), p->sq_entries);
if (size == SIZE_MAX) {
- io_mem_free(ctx->rings);
- ctx->rings = NULL;
+ io_rings_free(ctx);
return -EOVERFLOW;
}
ptr = io_mem_alloc(size);
if (IS_ERR(ptr)) {
- io_mem_free(ctx->rings);
- ctx->rings = NULL;
+ io_rings_free(ctx);
return PTR_ERR(ptr);
}