linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Ren Yu <renyu@nfschina.com>, cl@linux.com
Cc: penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com,
	akpm@linux-foundation.org, roman.gushchin@linux.dev,
	42.hyeyoo@gmail.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, liqiong@nfschina.com,
	qixu@nfschina.com, hukun@nfschina.com, yuzhe@nfschina.com
Subject: Re: [PATCH] mm: check the function kmalloc_slab return value
Date: Tue, 14 Jun 2022 10:48:42 +0200	[thread overview]
Message-ID: <bb8d41fc-bd13-9563-7c54-2850f131e835@suse.cz> (raw)
In-Reply-To: <20220614083939.13508-1-renyu@nfschina.com>

On 6/14/22 10:39, Ren Yu wrote:
> As the possible failure of the kmalloc_slab,
> it should be better to check it.

AFAIK failure is not possible, kmalloc_slab() is not an allocation function,
it just returns a member of kmalloc_caches array, which is initialized
elsewhere and shouldn't contain NULLs. So the patch seems unnecessary to me.

> Signed-off-by: Ren Yu <renyu@nfschina.com>
> Reported-by: kernel test robot <lkp@intel.com>
> ---
> v2:
> - fix build waring integer from pointer without a cast
> ---
> ---
>  mm/slab.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/mm/slab.c b/mm/slab.c
> index f8cd00f4ba13..72135e555827 100644
> --- a/mm/slab.c
> +++ b/mm/slab.c
> @@ -2064,6 +2064,8 @@ int __kmem_cache_create(struct kmem_cache *cachep, slab_flags_t flags)
>  	if (OFF_SLAB(cachep)) {
>  		cachep->freelist_cache =
>  			kmalloc_slab(cachep->freelist_size, 0u);
> +		if (unlikely(ZERO_OR_NULL_PTR(cachep->freelist_cache)))

The usual way is "if (!cachep->freelist_cache)". Not sure why check for ZERO.

> +			return cachep->freelist_cache;

So in case of NULL this would return NULL, thus 0, but __kmem_cache_create()
return 0 on success, so it's wrong. You would have to return e.g. -ENOMEM.

>  	}
>  
>  	err = setup_cpu_cache(cachep, gfp);



  reply	other threads:[~2022-06-14  8:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-13 10:24 Ren Yu
2022-06-13 13:37 ` kernel test robot
2022-06-14  8:39 ` Ren Yu
2022-06-14  8:48   ` Vlastimil Babka [this message]
2022-06-14  9:26     ` tury
2022-06-14 11:47       ` Vlastimil Babka
2022-06-14  9:23 ` [PATCH v2] mm, slab: " Ren Yu

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=bb8d41fc-bd13-9563-7c54-2850f131e835@suse.cz \
    --to=vbabka@suse.cz \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=hukun@nfschina.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liqiong@nfschina.com \
    --cc=penberg@kernel.org \
    --cc=qixu@nfschina.com \
    --cc=renyu@nfschina.com \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=yuzhe@nfschina.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