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 11829C433EF for ; Mon, 6 Jun 2022 02:09:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F7E78D0002; Sun, 5 Jun 2022 22:09:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A35B8D0001; Sun, 5 Jun 2022 22:09:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 590658D0002; Sun, 5 Jun 2022 22:09:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 469A78D0001 for ; Sun, 5 Jun 2022 22:09:09 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1AA79203CE for ; Mon, 6 Jun 2022 02:09:09 +0000 (UTC) X-FDA: 79546178418.14.876C7D6 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf22.hostedemail.com (Postfix) with ESMTP id 99241C003E for ; Mon, 6 Jun 2022 02:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=4BYz+QAVVmrOzsJcEMx42CDop/axWeg3fqIEzS4Xzaw=; b=L8BqkKNDzQSNN3nv0/pPC0lx1S 3ktEPK2oDCypYLJCuvRY9kkp6vRk5vaC7m3594HFwYUbZnM4LGs0jPuRb2k+cxoNiXkSn6hVTUP8F so1yE85zwem4yjEL7ErXly8gmdVkNq7Nz3gnyXe/yVF6IYw9gpUoQ0u1lcBdfthkErzHe9qwFhpr5 fLxWWIz3blby47GKgaz1CUfmr6lAdTenjv839yhCt2Bfi6Pwtqu7l7IT2cvwV7EPZt/ZInNAJBZtJ htYLeQKGsEGABcPheb0RcbNEZKRKDOZyEmRgj3J5u2wRVIjiBCo9wWzCBE2geUzj8bPkPNYGxYarz FrZ40P4w==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1ny2At-00AErk-0z; Mon, 06 Jun 2022 02:08:59 +0000 Date: Mon, 6 Jun 2022 03:08:58 +0100 From: Matthew Wilcox To: Chen Wandun Cc: hughd@google.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@redhat.com, wangkefeng.wang@huawei.com Subject: Re: [PATCH v2 1/3] mm/shmem: check return value of shmem_init_inodecache Message-ID: References: <20220605035557.3957759-1-chenwandun@huawei.com> <20220605035557.3957759-2-chenwandun@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Stat-Signature: xpxjsr9ju1ept89q6y7wdhakty3f57ar Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=L8BqkKND; dmarc=none; spf=none (imf22.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 99241C003E X-HE-Tag: 1654481344-370055 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 Mon, Jun 06, 2022 at 09:34:13AM +0800, Chen Wandun wrote: > On 2022/6/5 19:49, Matthew Wilcox wrote: > > On Sun, Jun 05, 2022 at 11:55:55AM +0800, Chen Wandun wrote: > > > It will result in null pointer access if shmem_init_inodecache fail, > > > so check return value of shmem_init_inodecache > > You ignored my suggestion from v1. Here, let me write it out for you. > Hi Matthew, > I didn't ignore your suggestion,  some explanation is needed, sorry for > that. > > In V1, Kefeng point: > "kmem_cache_create return a pointer to the cache on success, NULL on > failure, > so error = -ENOMEM; is right :)" > > so, I look some similar code such as init_inodecache in kinds of file > system,  they all > return -ENOMEM on failure, so is it OK to return -ENOMEM on failure :) > > Besides,  kmem_cache_create return NULL on failure, maybe returning error > code > on failure is more proper, but it is another job. I literally wrote out what I think you should do instead. Stop arguing. > > +static int shmem_init_inodecache(void) > > { > > shmem_inode_cachep = kmem_cache_create("shmem_inode_cache", > > sizeof(struct shmem_inode_info), > > 0, SLAB_PANIC|SLAB_ACCOUNT, shmem_init_inode); > > + if (!shmem_inode_cachep) > > + return -ENOMEM; > > + return 0; > > } > > > > ... > > > > + error = shmem_init_inodecache(); > > + if (error) > > + goto out2; > > > > > > . >