Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp129219iof; Sun, 5 Jun 2022 23:14:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEDmCM4dbWSF3X3PiN/Dl+AVO4iGNwOUKSPuhz4vGzlsWYa7KSgrFVfzHQ7nIZfvNay9zk X-Received: by 2002:a17:902:e752:b0:165:1282:8d56 with SMTP id p18-20020a170902e75200b0016512828d56mr22948238plf.48.1654496056777; Sun, 05 Jun 2022 23:14:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654496056; cv=none; d=google.com; s=arc-20160816; b=LVGBKL/SEFirV9yKbORzlTJjLCtYKFVuXM8fsEBO3epvSt5ffRU8GWWLhGtyYLkDCP EzQr40cPg+CfwEvWCRl8rqFm7+BlmWhLga4qsK81ahQcocpwD6yHHx9TWDJTq8CVRSFJ rsgnxdMfO6FomAan3KDyilpJqd7a+5EKdaheZ3ca94QVj/7Y43wkyYvfrX+1qXya7wXM ZtuQU32bLNmqjMzkAKgMnmO+kLr7HbF3ZH3zLQwHMrDLLUxY8zwsJ1as3XOwIboD4P2g /+2RgU59a34nWTDQKl2ZjDI00vVZEK80+2mbKkMfMl682anEredsV1tBtvMKljuAYhks yXmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=4BYz+QAVVmrOzsJcEMx42CDop/axWeg3fqIEzS4Xzaw=; b=1C1aVfKIAgqGSzeyUJjxC6yvwB5b2u5Ybw/OWUyGHPwnecVV3DQAihCg5/hbWJ3bil 5GTxuVE/eQXDpSECnMHDog2albUu+iXPGcyVDfHFJ97cvQzuJ6GvJhixG1OVaQy/e0N4 TPOqDOg0B51P4+NMQyccEx+Y84gAReKuj88OlNwVgUmvQT6YO579iysZEpd5/Bd+xGzl t6DI6c2RakqmZvncuGf8NZWcXhdISwhddWMew7kVyPAb/3tM+efqCXVapv2fzTfxH2Ir pRPu80yBbXJ+gD+jgeQEj6zK69VKgkaBSo46NJdBymtwjPZMrJBhn6ZC6l47gPKYhaLj lPFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=L8BqkKND; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id t6-20020a170902bc4600b0016366bfb1c2si19208013plz.424.2022.06.05.23.14.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 23:14:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=L8BqkKND; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6B17C5C75C; Sun, 5 Jun 2022 21:53:09 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349038AbiFFCJP (ORCPT + 99 others); Sun, 5 Jun 2022 22:09:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240339AbiFFCJO (ORCPT ); Sun, 5 Jun 2022 22:09:14 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA3712C121 for ; Sun, 5 Jun 2022 19:09:10 -0700 (PDT) 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-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; > > > > > > . >