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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6774C43334 for ; Mon, 6 Jun 2022 01:34:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351970AbiFFBeT (ORCPT ); Sun, 5 Jun 2022 21:34:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348931AbiFFBeR (ORCPT ); Sun, 5 Jun 2022 21:34:17 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E525222293 for ; Sun, 5 Jun 2022 18:34:15 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LGbbf6K6DzjXLj; Mon, 6 Jun 2022 09:33:18 +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 09:34:14 +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 09:34:13 +0800 Message-ID: Date: Mon, 6 Jun 2022 09:34:13 +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: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500002.china.huawei.com (7.185.36.229) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > +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; > > > .