Skip to content

Commit e27cef8

Browse files
committed
io_uring: return error pointer from io_mem_alloc()
In preparation for having more than one time of ring allocator, make the existing one return valid/error-pointer rather than just NULL. Signed-off-by: Jens Axboe <[email protected]>
1 parent 9b1b58c commit e27cef8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

io_uring/io_uring.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,8 +2691,12 @@ static void io_mem_free(void *ptr)
26912691
static void *io_mem_alloc(size_t size)
26922692
{
26932693
gfp_t gfp = GFP_KERNEL_ACCOUNT | __GFP_ZERO | __GFP_NOWARN | __GFP_COMP;
2694+
void *ret;
26942695

2695-
return (void *) __get_free_pages(gfp, get_order(size));
2696+
ret = (void *) __get_free_pages(gfp, get_order(size));
2697+
if (ret)
2698+
return ret;
2699+
return ERR_PTR(-ENOMEM);
26962700
}
26972701

26982702
static unsigned long rings_size(struct io_ring_ctx *ctx, unsigned int sq_entries,
@@ -3652,6 +3656,7 @@ static __cold int io_allocate_scq_urings(struct io_ring_ctx *ctx,
36523656
{
36533657
struct io_rings *rings;
36543658
size_t size, sq_array_offset;
3659+
void *ptr;
36553660

36563661
/* make sure these are sane, as we already accounted them */
36573662
ctx->sq_entries = p->sq_entries;
@@ -3662,8 +3667,8 @@ static __cold int io_allocate_scq_urings(struct io_ring_ctx *ctx,
36623667
return -EOVERFLOW;
36633668

36643669
rings = io_mem_alloc(size);
3665-
if (!rings)
3666-
return -ENOMEM;
3670+
if (IS_ERR(rings))
3671+
return PTR_ERR(rings);
36673672

36683673
ctx->rings = rings;
36693674
ctx->sq_array = (u32 *)((char *)rings + sq_array_offset);
@@ -3682,13 +3687,14 @@ static __cold int io_allocate_scq_urings(struct io_ring_ctx *ctx,
36823687
return -EOVERFLOW;
36833688
}
36843689

3685-
ctx->sq_sqes = io_mem_alloc(size);
3686-
if (!ctx->sq_sqes) {
3690+
ptr = io_mem_alloc(size);
3691+
if (IS_ERR(ptr)) {
36873692
io_mem_free(ctx->rings);
36883693
ctx->rings = NULL;
3689-
return -ENOMEM;
3694+
return PTR_ERR(ptr);
36903695
}
36913696

3697+
ctx->sq_sqes = ptr;
36923698
return 0;
36933699
}
36943700

0 commit comments

Comments
 (0)