linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next] mm/folio-compat.c: folio should not be NULL when it is referenced
@ 2021-08-23  0:47 Yi Wang
  2021-08-23  1:05 ` Matthew Wilcox
  0 siblings, 1 reply; 2+ messages in thread
From: Yi Wang @ 2021-08-23  0:47 UTC (permalink / raw)
  To: akpm
  Cc: linux-mm, linux-kernel, xue.zhihong, wang.yi59, jiang.xuexin,
	zealci, Changcheng Deng


[-- Attachment #1.1: Type: text/plain, Size: 996 bytes --]

From: Changcheng Deng <deng.changcheng@zte.com.cn>

A bug was found by coccinelle:
folio is NULL but dereferenced
Therefore,added a check to make sure 'folio' is not NULL.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Changcheng Deng <deng.changcheng@zte.com.cn>
Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
---
 mm/folio-compat.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/folio-compat.c b/mm/folio-compat.c
index 5b6ae1d..bee45e7 100644
--- a/mm/folio-compat.c
+++ b/mm/folio-compat.c
@@ -123,8 +123,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))
-		return &folio->page;
+	if ((fgp_flags & FGP_HEAD) || xa_is_value(folio))
+		if (folio != NULL)
+			return &folio->page;
 	return folio_file_page(folio, index);
 }
 EXPORT_SYMBOL(pagecache_get_page);
-- 
1.8.3.1

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

end of thread, other threads:[~2021-08-23  1:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-23  0:47 [PATCH linux-next] mm/folio-compat.c: folio should not be NULL when it is referenced Yi Wang
2021-08-23  1:05 ` 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).