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 <axboe@kernel.dk>
This commit is contained in:
parent
9b1b58cacc
commit
e27cef86a0
|
@ -2691,8 +2691,12 @@ static void io_mem_free(void *ptr)
|
||||||
static void *io_mem_alloc(size_t size)
|
static void *io_mem_alloc(size_t size)
|
||||||
{
|
{
|
||||||
gfp_t gfp = GFP_KERNEL_ACCOUNT | __GFP_ZERO | __GFP_NOWARN | __GFP_COMP;
|
gfp_t gfp = GFP_KERNEL_ACCOUNT | __GFP_ZERO | __GFP_NOWARN | __GFP_COMP;
|
||||||
|
void *ret;
|
||||||
|
|
||||||
return (void *) __get_free_pages(gfp, get_order(size));
|
ret = (void *) __get_free_pages(gfp, get_order(size));
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
return ERR_PTR(-ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned long rings_size(struct io_ring_ctx *ctx, unsigned int sq_entries,
|
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,
|
||||||
{
|
{
|
||||||
struct io_rings *rings;
|
struct io_rings *rings;
|
||||||
size_t size, sq_array_offset;
|
size_t size, sq_array_offset;
|
||||||
|
void *ptr;
|
||||||
|
|
||||||
/* make sure these are sane, as we already accounted them */
|
/* make sure these are sane, as we already accounted them */
|
||||||
ctx->sq_entries = p->sq_entries;
|
ctx->sq_entries = p->sq_entries;
|
||||||
|
@ -3662,8 +3667,8 @@ static __cold int io_allocate_scq_urings(struct io_ring_ctx *ctx,
|
||||||
return -EOVERFLOW;
|
return -EOVERFLOW;
|
||||||
|
|
||||||
rings = io_mem_alloc(size);
|
rings = io_mem_alloc(size);
|
||||||
if (!rings)
|
if (IS_ERR(rings))
|
||||||
return -ENOMEM;
|
return PTR_ERR(rings);
|
||||||
|
|
||||||
ctx->rings = rings;
|
ctx->rings = rings;
|
||||||
ctx->sq_array = (u32 *)((char *)rings + sq_array_offset);
|
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,
|
||||||
return -EOVERFLOW;
|
return -EOVERFLOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->sq_sqes = io_mem_alloc(size);
|
ptr = io_mem_alloc(size);
|
||||||
if (!ctx->sq_sqes) {
|
if (IS_ERR(ptr)) {
|
||||||
io_mem_free(ctx->rings);
|
io_mem_free(ctx->rings);
|
||||||
ctx->rings = NULL;
|
ctx->rings = NULL;
|
||||||
return -ENOMEM;
|
return PTR_ERR(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx->sq_sqes = ptr;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue