[PATCH] io_uring/memmap: return bool from io_mem_alloc_compound()

Caleb Sander Mateos posted 1 patch 2 months ago
io_uring/memmap.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
[PATCH] io_uring/memmap: return bool from io_mem_alloc_compound()
Posted by Caleb Sander Mateos 2 months ago
io_mem_alloc_compound() returns either ERR_PTR(-ENOMEM) or a virtual
address for the allocated memory, but its caller just checks whether the
result is an error. Return a bool success value instead.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
---
 io_uring/memmap.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/io_uring/memmap.c b/io_uring/memmap.c
index 2e99dffddfc5..b53733a54074 100644
--- a/io_uring/memmap.c
+++ b/io_uring/memmap.c
@@ -13,30 +13,30 @@
 #include "memmap.h"
 #include "kbuf.h"
 #include "rsrc.h"
 #include "zcrx.h"
 
-static void *io_mem_alloc_compound(struct page **pages, int nr_pages,
-				   size_t size, gfp_t gfp)
+static bool io_mem_alloc_compound(struct page **pages, int nr_pages,
+				  size_t size, gfp_t gfp)
 {
 	struct page *page;
 	int i, order;
 
 	order = get_order(size);
 	if (order > MAX_PAGE_ORDER)
-		return ERR_PTR(-ENOMEM);
+		return false;
 	else if (order)
 		gfp |= __GFP_COMP;
 
 	page = alloc_pages(gfp, order);
 	if (!page)
-		return ERR_PTR(-ENOMEM);
+		return false;
 
 	for (i = 0; i < nr_pages; i++)
 		pages[i] = page + i;
 
-	return page_address(page);
+	return true;
 }
 
 struct page **io_pin_pages(unsigned long uaddr, unsigned long len, int *npages)
 {
 	unsigned long start, end, nr_pages;
@@ -157,18 +157,16 @@ static int io_region_allocate_pages(struct io_ring_ctx *ctx,
 {
 	gfp_t gfp = GFP_KERNEL_ACCOUNT | __GFP_ZERO | __GFP_NOWARN;
 	size_t size = (size_t) mr->nr_pages << PAGE_SHIFT;
 	unsigned long nr_allocated;
 	struct page **pages;
-	void *p;
 
 	pages = kvmalloc_array(mr->nr_pages, sizeof(*pages), gfp);
 	if (!pages)
 		return -ENOMEM;
 
-	p = io_mem_alloc_compound(pages, mr->nr_pages, size, gfp);
-	if (!IS_ERR(p)) {
+	if (io_mem_alloc_compound(pages, mr->nr_pages, size, gfp)) {
 		mr->flags |= IO_REGION_F_SINGLE_REF;
 		goto done;
 	}
 
 	nr_allocated = alloc_pages_bulk_node(gfp, NUMA_NO_NODE,
-- 
2.45.2
Re: [PATCH] io_uring/memmap: return bool from io_mem_alloc_compound()
Posted by Jens Axboe 1 month, 2 weeks ago
On Wed, 15 Oct 2025 11:25:54 -0600, Caleb Sander Mateos wrote:
> io_mem_alloc_compound() returns either ERR_PTR(-ENOMEM) or a virtual
> address for the allocated memory, but its caller just checks whether the
> result is an error. Return a bool success value instead.
> 
> 

Applied, thanks!

[1/1] io_uring/memmap: return bool from io_mem_alloc_compound()
      commit: 13bbfacf0e330f72875f93cdc709efd54abcfa8d

Best regards,
-- 
Jens Axboe
Re: [PATCH] io_uring/memmap: return bool from io_mem_alloc_compound()
Posted by Caleb Sander Mateos 1 month, 2 weeks ago
Hi Jens,
Any comments on this minor cleanup?

Thanks,
Caleb

On Wed, Oct 15, 2025 at 10:25 AM Caleb Sander Mateos
<csander@purestorage.com> wrote:
>
> io_mem_alloc_compound() returns either ERR_PTR(-ENOMEM) or a virtual
> address for the allocated memory, but its caller just checks whether the
> result is an error. Return a bool success value instead.
>
> Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
> ---
>  io_uring/memmap.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/io_uring/memmap.c b/io_uring/memmap.c
> index 2e99dffddfc5..b53733a54074 100644
> --- a/io_uring/memmap.c
> +++ b/io_uring/memmap.c
> @@ -13,30 +13,30 @@
>  #include "memmap.h"
>  #include "kbuf.h"
>  #include "rsrc.h"
>  #include "zcrx.h"
>
> -static void *io_mem_alloc_compound(struct page **pages, int nr_pages,
> -                                  size_t size, gfp_t gfp)
> +static bool io_mem_alloc_compound(struct page **pages, int nr_pages,
> +                                 size_t size, gfp_t gfp)
>  {
>         struct page *page;
>         int i, order;
>
>         order = get_order(size);
>         if (order > MAX_PAGE_ORDER)
> -               return ERR_PTR(-ENOMEM);
> +               return false;
>         else if (order)
>                 gfp |= __GFP_COMP;
>
>         page = alloc_pages(gfp, order);
>         if (!page)
> -               return ERR_PTR(-ENOMEM);
> +               return false;
>
>         for (i = 0; i < nr_pages; i++)
>                 pages[i] = page + i;
>
> -       return page_address(page);
> +       return true;
>  }
>
>  struct page **io_pin_pages(unsigned long uaddr, unsigned long len, int *npages)
>  {
>         unsigned long start, end, nr_pages;
> @@ -157,18 +157,16 @@ static int io_region_allocate_pages(struct io_ring_ctx *ctx,
>  {
>         gfp_t gfp = GFP_KERNEL_ACCOUNT | __GFP_ZERO | __GFP_NOWARN;
>         size_t size = (size_t) mr->nr_pages << PAGE_SHIFT;
>         unsigned long nr_allocated;
>         struct page **pages;
> -       void *p;
>
>         pages = kvmalloc_array(mr->nr_pages, sizeof(*pages), gfp);
>         if (!pages)
>                 return -ENOMEM;
>
> -       p = io_mem_alloc_compound(pages, mr->nr_pages, size, gfp);
> -       if (!IS_ERR(p)) {
> +       if (io_mem_alloc_compound(pages, mr->nr_pages, size, gfp)) {
>                 mr->flags |= IO_REGION_F_SINGLE_REF;
>                 goto done;
>         }
>
>         nr_allocated = alloc_pages_bulk_node(gfp, NUMA_NO_NODE,
> --
> 2.45.2
>
Re: [PATCH] io_uring/memmap: return bool from io_mem_alloc_compound()
Posted by Jens Axboe 1 month, 2 weeks ago
On 11/3/25 1:03 PM, Caleb Sander Mateos wrote:
> Hi Jens,
> Any comments on this minor cleanup?

Looks fine, arrived while I was on PTO and apparently got lost in
the noise... Applied now.

-- 
Jens Axboe