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 33C36C43334 for ; Mon, 6 Jun 2022 02:59:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70AA28D0003; Sun, 5 Jun 2022 22:59:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BBFD8D0002; Sun, 5 Jun 2022 22:59:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AAF58D0003; Sun, 5 Jun 2022 22:59:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4C1C28D0002 for ; Sun, 5 Jun 2022 22:59:33 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 08B182053F for ; Mon, 6 Jun 2022 02:59:33 +0000 (UTC) X-FDA: 79546305426.30.7453707 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf05.hostedemail.com (Postfix) with ESMTP id D5E6910002A for ; Mon, 6 Jun 2022 02:58:52 +0000 (UTC) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LGdTY1Mr1zjXSj; Mon, 6 Jun 2022 10:58:09 +0800 (CST) Received: from dggpemm500002.china.huawei.com (7.185.36.229) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 6 Jun 2022 10:58:58 +0800 Received: from [10.174.178.178] (10.174.178.178) by dggpemm500002.china.huawei.com (7.185.36.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 6 Jun 2022 10:58:58 +0800 Message-ID: Date: Mon, 6 Jun 2022 10:58:56 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.0.3 Subject: Re: [PATCH v2 1/3] mm/shmem: check return value of shmem_init_inodecache To: Matthew Wilcox CC: , , , , , References: <20220605035557.3957759-1-chenwandun@huawei.com> <20220605035557.3957759-2-chenwandun@huawei.com> From: Chen Wandun In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.178] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500002.china.huawei.com (7.185.36.229) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: D5E6910002A Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf05.hostedemail.com: domain of chenwandun@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=chenwandun@huawei.com X-Stat-Signature: 1xnqgk1kzwhrwpoendr6qmx6wfsg7qib X-Rspam-User: X-HE-Tag: 1654484332-854394 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/6/6 10:08, Matthew Wilcox 写道: > 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; Oh, I misunderstood what you said, feel so sorry. I will send a new version. Thanks. >>> >>> >>> . > .