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 E2475C43334 for ; Tue, 14 Jun 2022 11:47:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0BC968D0003; Tue, 14 Jun 2022 07:47:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 06C9E8D0001; Tue, 14 Jun 2022 07:47:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E76058D0003; Tue, 14 Jun 2022 07:47:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D5B418D0001 for ; Tue, 14 Jun 2022 07:47:38 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B198D618C0 for ; Tue, 14 Jun 2022 11:47:38 +0000 (UTC) X-FDA: 79576666596.05.764B837 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf16.hostedemail.com (Postfix) with ESMTP id B9117180093 for ; Tue, 14 Jun 2022 11:47:37 +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-out1.suse.de (Postfix) with ESMTPS id C9BDA21B23; Tue, 14 Jun 2022 11:47:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1655207255; 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=te73DX5kggSfnajOVBmsnuuS8V2hl4yR3sgi0lsOK+M=; b=0aA9MJYYVykJJ7t/bYkVScInYHsGVQV/AdPzpotM/Cim+yIvxT4YZoEudKNODz/67pM4F7 pKgrlpT4FcoVNWxC1WVZLUNTNmMHNe6cwhVAn1cNb1duuQTenoeT3VbhJk0eaX8zFaC41U cr9huxnBP8vIgF3zQliFznSAXbmH0pg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1655207255; 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=te73DX5kggSfnajOVBmsnuuS8V2hl4yR3sgi0lsOK+M=; b=nW75kCYZDixcMtaGdtpfvRxu+/Rr9nI5dsYWSjemPlrB58A1PkhobH2OUYgU5+no/OJntU GJ/f7dQb1TZY8VDg== 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 9A963139EC; Tue, 14 Jun 2022 11:47:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6GYoJVd1qGLLeQAAMHmgww (envelope-from ); Tue, 14 Jun 2022 11:47:35 +0000 Message-ID: Date: Tue, 14 Jun 2022 13:47:35 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH] mm: check the function kmalloc_slab return value Content-Language: en-US To: tury , 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: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655207258; 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=te73DX5kggSfnajOVBmsnuuS8V2hl4yR3sgi0lsOK+M=; b=5bK6lK7kR+yZZrx34+P/63PFS73gOcZrXK/+wxYvFZIx6hlSzkY/nsn2zXNuaULjJaUhPV 4CF0HB+CL6UxS1oGfVweswPWmTACjKM5D5+op2B04O2OwWW7J8UK1UuDcLhRlkgwxh4MNF SDxdw9Fl9GRmvy42RKC2C5JN/pT0Do0= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=0aA9MJYY; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=nW75kCYZ; spf=pass (imf16.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655207258; a=rsa-sha256; cv=none; b=Dp5EiEhHRl9bMV4aJYIVmvj8wG/LSt6ktrkkKNcDK/6Jk811aPg+CA+C8rUSpTOnyYHvgP k77ETfEEY9uQZ5H+QSHgCj06OqqTkp3bYhBlHFNvokym+lp+NmJKdwv/A8dH02OubRBaBE VVXGGSL3klM1MQ5lIOh0X78G3ovJbI8= X-Stat-Signature: 1ccd1uszyzsowujegmg47mtbhy6iqyot X-Rspamd-Queue-Id: B9117180093 X-Rspamd-Server: rspam11 X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=0aA9MJYY; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=nW75kCYZ; spf=pass (imf16.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-HE-Tag: 1655207257-991074 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 11:26, tury wrote: > > > 在 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 However that was meant just for your information/learning, the patch is still unecessary as I wrote above, so I will not merge it so we don't complicate the code needlessly. >> >>>       } >>>         err = setup_cpu_cache(cachep, gfp); >> >