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 EDE78C433F5 for ; Tue, 26 Apr 2022 21:17:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27E506B0073; Tue, 26 Apr 2022 17:17:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 22E336B0074; Tue, 26 Apr 2022 17:17:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F6246B0075; Tue, 26 Apr 2022 17:17:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id F30FE6B0073 for ; Tue, 26 Apr 2022 17:17:50 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BF14621017 for ; Tue, 26 Apr 2022 21:17:50 +0000 (UTC) X-FDA: 79400292300.13.F1BEE0F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id A87D710004D for ; Tue, 26 Apr 2022 21:17:48 +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-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=h0WM/OGYr1vmddkP3aThoTDj/4ylnz0kGYAAy3EuZGE=; b=kyguCSba/X6mQN+uANNGnuh6F/ AF0v4xllc6XsTsqebSYH2ppi/bm/62UZRT13hR9l9rtDgtTieEpaXnocYc/Q7Qv/W7WklIsbeiE0i 4QinJ/i97z7pcmWJkvkHNutWrYDjeyk3/FfmiicUPHaCdT3PjHE5Z2gwSLTNO3vSrGXTwibBwYuTF V4Ncqn0p2LHcsNVDsGEG5o4VTM9R2lqV4xtixba06P7K7mPYZ/vNYf1mZJfnAzpyrXa3txdP8ZomX jL0lgbQ9BMmLmHEzdAaLD1Pk1l9F69L3WKKepkohrtPADyPob5E6r0BOoaWDqpzTQSk0DpWHDIh4n ucWqiC9A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1njSYz-00A1ET-5j; Tue, 26 Apr 2022 21:17:37 +0000 Date: Tue, 26 Apr 2022 22:17:37 +0100 From: Matthew Wilcox To: Andrew Morton Cc: Wan Jiabing , Vlastimil Babka , David Howells , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Julia Lawall Subject: Re: [PATCH] mm/filemap: Fix NULL pointer dereference in pagecache_get_page Message-ID: References: <20220426082549.590899-1-wanjiabing@vivo.com> <20220426140641.cc78a429e1fa32ed0e15520b@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220426140641.cc78a429e1fa32ed0e15520b@linux-foundation.org> X-Rspamd-Queue-Id: A87D710004D X-Stat-Signature: k5dqq6dgd1nnhrb8r6wehug3ymyrq8z9 X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=kyguCSba; spf=none (imf14.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam09 X-HE-Tag: 1651007868-836652 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 Tue, Apr 26, 2022 at 02:06:41PM -0700, Andrew Morton wrote: > On Tue, 26 Apr 2022 13:08:08 +0100 Matthew Wilcox wrote: > > > On Tue, Apr 26, 2022 at 04:25:48PM +0800, Wan Jiabing wrote: > > > Fix following coccicheck error: > > > mm/folio-compat.c:128:17-21: ERROR: folio is NULL but dereferenced. > > > folio = __filemap_get_folio(mapping, index, fgp_flags, gfp); > > > - if ((fgp_flags & FGP_HEAD) || !folio || xa_is_value(folio)) > > > + if (!folio) > > > + return NULL; > > > + if ((fgp_flags & FGP_HEAD) || xa_is_value(folio)) > > > return &folio->page; > > > > That doesn't dereference the folio. Coccicheck is wrong. > > Doing > > return &(0->page); > > is a rather obscure way of doing `return NULL;'. > > I agree the patch doesn't fix anything, but it results in saner-looking code? I suppose that's in the eye of the beholder? The original code makes more sense to me. Besides, it's in the folio-compat file; nobody should be looking at that except to figure out "What function should I be transitioning to?"