In extreme cases, memory may not be available. so we should be clean up memory. Signed-off-by: Jackie Liu <liuyun01@xxxxxxxxxx> --- fs/io_uring.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 310f8d1..4430429 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -2951,6 +2951,7 @@ static int io_allocate_scq_urings(struct io_ring_ctx *ctx, struct io_sq_ring *sq_ring; struct io_cq_ring *cq_ring; size_t size; + int ret; sq_ring = io_mem_alloc(struct_size(sq_ring, array, p->sq_entries)); if (!sq_ring) @@ -2963,16 +2964,22 @@ static int io_allocate_scq_urings(struct io_ring_ctx *ctx, ctx->sq_entries = sq_ring->ring_entries; size = array_size(sizeof(struct io_uring_sqe), p->sq_entries); - if (size == SIZE_MAX) - return -EOVERFLOW; + if (size == SIZE_MAX) { + ret = -EOVERFLOW; + goto err; + } ctx->sq_sqes = io_mem_alloc(size); - if (!ctx->sq_sqes) - return -ENOMEM; + if (!ctx->sq_sqes) { + ret = -ENOMEM; + goto err; + } cq_ring = io_mem_alloc(struct_size(cq_ring, cqes, p->cq_entries)); - if (!cq_ring) - return -ENOMEM; + if (!cq_ring) { + ret = -ENOMEM; + goto err1; + } ctx->cq_ring = cq_ring; cq_ring->ring_mask = p->cq_entries - 1; @@ -2980,6 +2987,12 @@ static int io_allocate_scq_urings(struct io_ring_ctx *ctx, ctx->cq_mask = cq_ring->ring_mask; ctx->cq_entries = cq_ring->ring_entries; return 0; + +err1: + io_mem_free(ctx->sq_sqes); +err: + io_mem_free(ctx->sq_ring); + return ret; } /* -- 2.7.4