linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/vmalloc: Add check for KMEM_CACHE
Date: Thu, 24 Nov 2022 04:25:25 +0000	[thread overview]
Message-ID: <Y37yNRs/43WKnHxO@casper.infradead.org> (raw)
In-Reply-To: <20221124040226.17953-1-jiasheng@iscas.ac.cn>

On Thu, Nov 24, 2022 at 12:02:26PM +0800, Jiasheng Jiang wrote:
> As KMEM_CACHE may return NULL pointer, it should
> be better to check the return value in order to
> avoid NULL pointer dereference in kmem_cache_zalloc.

You've made the code more complex.  And for what?  If that
call fails, the system will not boot under any circumstances.

NAK this patch, and any more like it.

> Fixes: 68ad4a330433 ("mm/vmalloc.c: keep track of free blocks for vmap allocation")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>  mm/vmalloc.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index ccaa461998f3..df3e59f614cc 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -2426,15 +2426,17 @@ void __init vmalloc_init(void)
>  	}
>  
>  	/* Import existing vmlist entries. */
> -	for (tmp = vmlist; tmp; tmp = tmp->next) {
> -		va = kmem_cache_zalloc(vmap_area_cachep, GFP_NOWAIT);
> -		if (WARN_ON_ONCE(!va))
> -			continue;
> +	if (!WARN_ON_ONCE(!vmap_area_cachep)) {
> +		for (tmp = vmlist; tmp; tmp = tmp->next) {
> +			va = kmem_cache_zalloc(vmap_area_cachep, GFP_NOWAIT);
> +			if (WARN_ON_ONCE(!va))
> +				continue;
>  
> -		va->va_start = (unsigned long)tmp->addr;
> -		va->va_end = va->va_start + tmp->size;
> -		va->vm = tmp;
> -		insert_vmap_area(va, &vmap_area_root, &vmap_area_list);
> +			va->va_start = (unsigned long)tmp->addr;
> +			va->va_end = va->va_start + tmp->size;
> +			va->vm = tmp;
> +			insert_vmap_area(va, &vmap_area_root, &vmap_area_list);
> +		}
>  	}
>  
>  	/*
> -- 
> 2.25.1
> 
> 


  reply	other threads:[~2022-11-24  4:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-24  4:02 Jiasheng Jiang
2022-11-24  4:25 ` Matthew Wilcox [this message]
2022-11-24  4:25 ` Andrew Morton

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=Y37yNRs/43WKnHxO@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=jiasheng@iscas.ac.cn \
    --cc=linux-kernel@vger.kernel.org \
    --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