linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/filemap: Fix NULL pointer dereference in pagecache_get_page
@ 2022-04-26  8:25 Wan Jiabing
  2022-04-26 12:08 ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: Wan Jiabing @ 2022-04-26  8:25 UTC (permalink / raw)
  To: Andrew Morton, Matthew Wilcox (Oracle),
	Vlastimil Babka, David Howells, linux-mm, linux-kernel
  Cc: Wan Jiabing

Fix following coccicheck error:
mm/folio-compat.c:128:17-21: ERROR: folio is NULL but dereferenced.

'folio' would be NULL when getting a reference to a folio failed.
Add a NULL check before dereferring 'folio'.

Fixes: 3f0c6a07fee6 ("mm/filemap: Add filemap_get_folio")
Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
---
 mm/folio-compat.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/folio-compat.c b/mm/folio-compat.c
index 46fa179e32fb..54b17c1246c4 100644
--- a/mm/folio-compat.c
+++ b/mm/folio-compat.c
@@ -124,7 +124,9 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
 	struct folio *folio;
 
 	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;
 	return folio_file_page(folio, index);
 }
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-26 21:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26  8:25 [PATCH] mm/filemap: Fix NULL pointer dereference in pagecache_get_page Wan Jiabing
2022-04-26 12:08 ` Matthew Wilcox
2022-04-26 21:06   ` Andrew Morton
2022-04-26 21:17     ` Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).