From patchwork Wed Jun 1 12:44:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Wandun X-Patchwork-Id: 12866855 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 4693BC433EF for ; Wed, 1 Jun 2022 12:23:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 193E38D0006; Wed, 1 Jun 2022 08:23:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 075EF8D0010; Wed, 1 Jun 2022 08:23:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE39A8D000E; Wed, 1 Jun 2022 08:23:27 -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 C64DF8D0006 for ; Wed, 1 Jun 2022 08:23:27 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 781EB33EB5 for ; Wed, 1 Jun 2022 12:23:27 +0000 (UTC) X-FDA: 79529582454.15.08C1E7C Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf28.hostedemail.com (Postfix) with ESMTP id 0B229C008A for ; Wed, 1 Jun 2022 12:22:46 +0000 (UTC) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LCpD73fdjzgYWl; Wed, 1 Jun 2022 20:21:43 +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; Wed, 1 Jun 2022 20:23:23 +0800 Received: from localhost.localdomain (10.175.112.125) 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; Wed, 1 Jun 2022 20:23:22 +0800 From: Chen Wandun To: , , , CC: Subject: [PATCH 1/4] mm/shmem: check return value of shmem_init_inodecache Date: Wed, 1 Jun 2022 20:44:14 +0800 Message-ID: <20220601124417.2872001-2-chenwandun@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601124417.2872001-1-chenwandun@huawei.com> References: <20220601124417.2872001-1-chenwandun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500002.china.huawei.com (7.185.36.229) X-CFilter-Loop: Reflected X-Stat-Signature: o6upgb44j51qet5p9ztiuhed1qhxdji3 X-Rspam-User: Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of chenwandun@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=chenwandun@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 0B229C008A X-HE-Tag: 1654086166-582078 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: It will result in null pointer access if shmem_init_inodecache fail, so check return value of shmem_init_inodecache Signed-off-by: Chen Wandun --- mm/shmem.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index d55dd972023a..80c361c3d82c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3776,11 +3776,13 @@ static void shmem_init_inode(void *foo) inode_init_once(&info->vfs_inode); } -static void shmem_init_inodecache(void) +static struct kmem_cache *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); + + return shmem_inode_cachep; } static void shmem_destroy_inodecache(void) @@ -3924,7 +3926,10 @@ void __init shmem_init(void) { int error; - shmem_init_inodecache(); + if (!shmem_init_inodecache()) { + error = -ENOMEM; + goto out2; + } error = register_filesystem(&shmem_fs_type); if (error) {