From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8785C433EF for ; Tue, 14 Jun 2022 09:26:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2EEC6B0209; Tue, 14 Jun 2022 05:26:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CDEF76B020B; Tue, 14 Jun 2022 05:26:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA6E76B020C; Tue, 14 Jun 2022 05:26:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id ABB926B0209 for ; Tue, 14 Jun 2022 05:26:45 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7AC7733D9E for ; Tue, 14 Jun 2022 09:26:45 +0000 (UTC) X-FDA: 79576311570.18.A4D491C Received: from mail.nfschina.com (mail.nfschina.com [124.16.136.209]) by imf14.hostedemail.com (Postfix) with ESMTP id E1E2310007A for ; Tue, 14 Jun 2022 09:26:44 +0000 (UTC) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 0D6781E80D90; Tue, 14 Jun 2022 17:25:24 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3IqDa6VMt13U; Tue, 14 Jun 2022 17:25:21 +0800 (CST) Received: from [172.30.24.122] (unknown [180.167.10.98]) (Authenticated sender: renyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id B331C1E80D5E; Tue, 14 Jun 2022 17:25:20 +0800 (CST) Subject: Re: [PATCH] mm: check the function kmalloc_slab return value To: Vlastimil Babka , 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 References: <20220613102438.27723-1-renyu@nfschina.com> <20220614083939.13508-1-renyu@nfschina.com> From: tury Message-ID: Date: Tue, 14 Jun 2022 17:26:40 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655198805; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LuvO/Ad/acGkxO8xXnAkhpOueBfKhDN+x0VGdlOK5dc=; b=0jVRHGlujMOd+bEflztpivTC2GqImkC59/+y2Qxth3/Fg40Iu8uK7gc8OsZcXt4XmZZYNM jpG8Wi24yhQ3ZKYNse1RWmxw/nvldedeF3yUqDNXiec2VwwknXg1ryrno7tVjyvoKCELap yWP/TFvbWaRmSD+CXOSLHD+ZMxRJNtA= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=none; spf=none (imf14.hostedemail.com: domain of renyu@nfschina.com has no SPF policy when checking 124.16.136.209) smtp.mailfrom=renyu@nfschina.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655198805; a=rsa-sha256; cv=none; b=HcF6F2W+7rCU0hNWgi6KiCBu//NrXg6cRYsVvgzVXCO+TgbeibZ8cES3apZaa893vjZ62Y Yu+1rZANT2eoe4totjURp1HF1IkgGWvi3eeCZjD6oMf2JvxJd2z4XkbaC3qbc47X7Qh8aN 7PekMwJMYgRJSumCZAiGH288Nc1yoFY= X-Rspamd-Queue-Id: E1E2310007A X-Rspam-User: X-Stat-Signature: gert8zqk5d5ctaguarpau5zn67coj4ir Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=none; spf=none (imf14.hostedemail.com: domain of renyu@nfschina.com has no SPF policy when checking 124.16.136.209) smtp.mailfrom=renyu@nfschina.com X-Rspamd-Server: rspam04 X-HE-Tag: 1655198804-807878 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 在 2022年06月14日 16:48, Vlastimil Babka 写道: > 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 >> Reported-by: kernel test robot >> --- >> 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. Thanks for the advice ,I'll be re-patching > >> } >> >> err = setup_cpu_cache(cachep, gfp); >