public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Caleb Sander Mateos <csander@purestorage.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] io_uring/memmap: return bool from io_mem_alloc_compound()
Date: Mon, 3 Nov 2025 12:03:49 -0800	[thread overview]
Message-ID: <CADUfDZq807sZ5ZMeX3adbV70Pjjbn299kTwyADhEiJqcxMO6xA@mail.gmail.com> (raw)
In-Reply-To: <20251015172555.2797238-1-csander@purestorage.com>

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
>

  reply	other threads:[~2025-11-03 20:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15 17:25 [PATCH] io_uring/memmap: return bool from io_mem_alloc_compound() Caleb Sander Mateos
2025-11-03 20:03 ` Caleb Sander Mateos [this message]
2025-11-03 20:07   ` Jens Axboe
2025-11-03 20:07 ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADUfDZq807sZ5ZMeX3adbV70Pjjbn299kTwyADhEiJqcxMO6xA@mail.gmail.com \
    --to=csander@purestorage.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox