linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: klourencodev@gmail.com, linux-mm@kvack.org,
	Christoph Hellwig <hch@infradead.org>
Cc: akpm@linux-foundation.org
Subject: Re: [PATCH] mm/mempool.c: set @elems slots to NULL once freed
Date: Wed, 24 Dec 2025 00:47:07 +0100	[thread overview]
Message-ID: <0b5f2c87-c180-4ada-9d37-f2e3d0071d9f@suse.cz> (raw)
In-Reply-To: <20251223231054.16061-1-klourencodev@gmail.com>

+Cc Christoph

On 12/24/25 00:10, klourencodev@gmail.com wrote:
> From: Kevin Lourenco <klourencodev@gmail.com>
> 
> This is documented in the function comment as "...and sets their
> slots in @elems to NULL.", but it was not followed.
> 
> We need to follow the NULL assignment, because elements newly returned
> to the pool must not be touched under any circumstances by the user.
> 
> Signed-off-by: Kevin Lourenco <klourencodev@gmail.com>
> ---
>  mm/mempool.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/mempool.c b/mm/mempool.c
> index c290e5261b47..1a2060304fd4 100644
> --- a/mm/mempool.c
> +++ b/mm/mempool.c
> @@ -674,7 +674,8 @@ unsigned int mempool_free_bulk(struct mempool *pool, void **elems,
>  	if (unlikely(READ_ONCE(pool->curr_nr) < pool->min_nr)) {
>  		spin_lock_irqsave(&pool->lock, flags);
>  		while (pool->curr_nr < pool->min_nr && freed < count) {
> -			add_element(pool, elems[freed++]);
> +			add_element(pool, elems[freed]);
> +			elems[freed++] = NULL;
>  			added = true;
>  		}
>  		spin_unlock_irqrestore(&pool->lock, flags);
> @@ -683,7 +684,8 @@ unsigned int mempool_free_bulk(struct mempool *pool, void **elems,
>  		/* Handle the min_nr = 0 edge case: */
>  		spin_lock_irqsave(&pool->lock, flags);
>  		if (likely(pool->curr_nr == 0)) {
> -			add_element(pool, elems[freed++]);
> +			add_element(pool, elems[freed]);
> +			elems[freed++] = NULL;
>  			added = true;
>  		}
>  		spin_unlock_irqrestore(&pool->lock, flags);



      reply	other threads:[~2025-12-23 23:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-23 23:10 klourencodev
2025-12-23 23:47 ` Vlastimil Babka [this message]

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=0b5f2c87-c180-4ada-9d37-f2e3d0071d9f@suse.cz \
    --to=vbabka@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=klourencodev@gmail.com \
    --cc=linux-mm@kvack.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