mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Fredrik Noring <fredrik.noring@gmail.com>
To: Amit Patole <amit.patole@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Christoph Hellwig <hch@lst.de>,
	Brendan Higgins <brendan.higgins@linux.dev>,
	David Gow <david@davidgow.net>, Rae Moar <raemoar63@gmail.com>,
	linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] lib/genalloc: don't dereference a NULL pool in gen_pool_dma_[z]alloc()
Date: Fri, 6 Nov 2026 19:46:20 +0100	[thread overview]
Message-ID: <au4gfAfX_p4D4L75@aerith> (raw)
In-Reply-To: <20261106-kunit-genalloc-v1-1-ba1ea397dfd8@gmail.com>

Hi Amit,

On Fri, Nov 06, 2026 at 09:02:32AM -0500, Amit Patole wrote:
> gen_pool_dma_alloc() returned NULL for a NULL pool since it was added.
> Commit cf394fc5f715 ("lib/genalloc.c: Add algorithm, align and zeroed
> family of DMA allocators") moved that check into
> gen_pool_dma_alloc_algo(), but gen_pool_dma_alloc() now reads
> pool->algo and pool->data before calling it, so a NULL pool is
> dereferenced instead. gen_pool_dma_zalloc(), added by the same commit,
> has the same problem. The _algo() and _align() variants still return
> NULL.
> 
> All in-tree callers check the pool before calling, so this is not
> known to be reachable today, but the four entry points disagree and
> the original behaviour is easy to restore. Check for a NULL pool before
> dereferencing it.

If this change is accepted, may I suggest that the corresponding
documentation

	@pool: pool to allocate from

is updated to (something like)

	@pool: pool to allocate from, or %NULL

as well? There seem to be 8 instances, but some of the others currently
don't accept %NULL, for example gen_pool_virt_to_phys(), which I suppose
could be made to return -1 in that case?

And then there's gen_pool_destroy(), which currently doesn't accept
%NULL either. Error paths can often be simplified if free/destroy/release/etc.
accept %NULL.

I'm not up-to-date with the latest NULL handling policy in the kernel,
but I think some inconsistencies can be found still. :-)

Fredrik

  reply	other threads:[~2026-11-06 18:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 14:02 [PATCH 0/2] lib/genalloc: fix a NULL pool check and add KUnit tests Amit Patole
2026-11-06 14:02 ` [PATCH 1/2] lib/genalloc: don't dereference a NULL pool in gen_pool_dma_[z]alloc() Amit Patole
2026-11-06 18:46   ` Fredrik Noring [this message]
2026-11-06 14:02 ` [PATCH 2/2] lib/tests: add KUnit tests for genalloc Amit Patole

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=au4gfAfX_p4D4L75@aerith \
    --to=fredrik.noring@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=amit.patole@gmail.com \
    --cc=brendan.higgins@linux.dev \
    --cc=david@davidgow.net \
    --cc=hch@lst.de \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=raemoar63@gmail.com \
    /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

all inboxes | Powered by JetHome®