Skip to content

Commit 9c189ee

Browse files
committed
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 <[email protected]>
1 parent e27cef8 commit 9c189ee

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

io_uring/io_uring.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,14 @@ static void io_mem_free(void *ptr)
26882688
free_compound_page(page);
26892689
}
26902690

2691+
static void io_rings_free(struct io_ring_ctx *ctx)
2692+
{
2693+
io_mem_free(ctx->rings);
2694+
io_mem_free(ctx->sq_sqes);
2695+
ctx->rings = NULL;
2696+
ctx->sq_sqes = NULL;
2697+
}
2698+
26912699
static void *io_mem_alloc(size_t size)
26922700
{
26932701
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)
28522860
mmdrop(ctx->mm_account);
28532861
ctx->mm_account = NULL;
28542862
}
2855-
io_mem_free(ctx->rings);
2856-
io_mem_free(ctx->sq_sqes);
2863+
io_rings_free(ctx);
28572864

28582865
percpu_ref_exit(&ctx->refs);
28592866
free_uid(ctx->user);
@@ -3682,15 +3689,13 @@ static __cold int io_allocate_scq_urings(struct io_ring_ctx *ctx,
36823689
else
36833690
size = array_size(sizeof(struct io_uring_sqe), p->sq_entries);
36843691
if (size == SIZE_MAX) {
3685-
io_mem_free(ctx->rings);
3686-
ctx->rings = NULL;
3692+
io_rings_free(ctx);
36873693
return -EOVERFLOW;
36883694
}
36893695

36903696
ptr = io_mem_alloc(size);
36913697
if (IS_ERR(ptr)) {
3692-
io_mem_free(ctx->rings);
3693-
ctx->rings = NULL;
3698+
io_rings_free(ctx);
36943699
return PTR_ERR(ptr);
36953700
}
36963701

0 commit comments

Comments
 (0)