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 EED5DC433EF for ; Tue, 14 Jun 2022 08:48:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F8DD8D0234; Tue, 14 Jun 2022 04:48:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A8378D0229; Tue, 14 Jun 2022 04:48:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26F568D0234; Tue, 14 Jun 2022 04:48: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 148A28D0229 for ; Tue, 14 Jun 2022 04:48:45 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D67D935895 for ; Tue, 14 Jun 2022 08:48:44 +0000 (UTC) X-FDA: 79576215768.08.F74BF0D Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf16.hostedemail.com (Postfix) with ESMTP id 60981180093 for ; Tue, 14 Jun 2022 08:48:44 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2D1E81F912; Tue, 14 Jun 2022 08:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1655196523; h=from:from:reply-to: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=zRzsb+awEOHYFKjt3mE5gpf5ido2LM1NkdZFLfpaEQk=; b=dsUn+lRVuRLA8O6klB2mHKbYa+5gMXCG6uMk/6JsYd2jD3DccV2Wgco1VPtgniJdTWyxgb QrTCprF4RiQF0pugULngVTBbvKyOu1OktQBUBg1DY9Wep3qGqOGevoyS16S/key7y9DMOY wsM2nfZm1ExLk4fi6Ifh6lHFbXS/EAw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1655196523; h=from:from:reply-to: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=zRzsb+awEOHYFKjt3mE5gpf5ido2LM1NkdZFLfpaEQk=; b=khzxj90wasL7hXFh+KDYQNF+T3xe/BLtY+TmDIvy5suQEp7WFCMzftja8vO6lcBPOxPXfS Vz/bCei2ctto00Aw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F025B1361C; Tue, 14 Jun 2022 08:48:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id AzkEOmpLqGIHKAAAMHmgww (envelope-from ); Tue, 14 Jun 2022 08:48:42 +0000 Message-ID: Date: Tue, 14 Jun 2022 10:48:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] mm: check the function kmalloc_slab return value Content-Language: en-US To: Ren Yu , 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: Vlastimil Babka In-Reply-To: <20220614083939.13508-1-renyu@nfschina.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=dsUn+lRV; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=khzxj90w; dmarc=none; spf=pass (imf16.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655196524; 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:dkim-signature; bh=zRzsb+awEOHYFKjt3mE5gpf5ido2LM1NkdZFLfpaEQk=; b=rnb/S91Ick/WWIQbc3PMmiUyfSEkzSc/6NhItdOo0OqbCoo9sQ5mNiixAYE95AyMua5hzM xFsSOaGXBynULdmOcFs/Z5RLIhEyiKaIaeB4efM81TjB4ZPMDYDC9wshHJ2FajLUGFXCwc vgrAxdA1HA76WDuqI0rhq7pJJqRBZTk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655196524; a=rsa-sha256; cv=none; b=eOvHmjguETo8j79s4aD2YNYxA6usMlEiKogPSzu6p19HptKXRC+UZaywUwCV0+4LOTrqa6 Q6e5kDnxDyf8PUTBlirJsAc/YZ5oPHDq/QB5IqkL9twOlXcDfObvuu4qz0ml9mCESXRPAG 7HKKSVCBEVbA2Mn1cbZcPUcKvt4Tm8E= X-Stat-Signature: tbaaqumgjruwgsycbsnzxw4tp4bdnw3d X-Rspamd-Queue-Id: 60981180093 X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=dsUn+lRV; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=khzxj90w; dmarc=none; spf=pass (imf16.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Rspamd-Server: rspam10 X-HE-Tag: 1655196524-478057 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: 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. > } > > err = setup_cpu_cache(cachep, gfp);