Re: [PATCH] mm/filemap: Fix NULL pointer dereference in pagecache_get_page

From: Andrew Morton
Date: Tue Apr 26 2022 - 17:06:50 EST


On Tue, 26 Apr 2022 13:08:08 +0100 Matthew Wilcox <willy@xxxxxxxxxxxxx> 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?