Skip to contentSkip to conversation

io_uring/memmap: return bool from io_mem_alloc_compound()

PATCH Applied Caleb Sander Mateos 2 participants 4 messages Oct 15, 2025 – Nov 3, 2025 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_uring/memmap: return bool from io_mem_alloc_compound()

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.

---
 io_uring/memmap.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
io_uring/memmap.c +6 -8
index 2e99dffddfc5..b53733a54074 100644
@@ -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,
Signature · 1 line
2.45.2
#1 lore raw

Hi Jens,
Any comments on this minor cleanup?

Thanks,
Caleb

Quoted 73 lines · Caleb Sander Mateos

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.

---
 io_uring/memmap.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
io_uring/memmap.c +6 -9
index 2e99dffddfc5..b53733a54074 100644
@@ -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

maintainer
#2 lore raw
Quoted 2 lines · Caleb Sander Mateos

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.

Signature · 1 line
Jens Axboe
maintainer Applied
#3 lore raw
In reply to Caleb Sander Mateos
Quoted 5 lines · Caleb Sander Mateos

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,

Signature · 1 line
Jens Axboe