2022-03-11 22:41:44

by Jiasheng Jiang

[permalink] [raw]
Subject: [PATCH] gfs2: Add check for mempool_alloc

As the potential failure of mempool_alloc(),
it could return NULL pointer.
Therefore, it should be better to check it
in order to avoid the dereference of the NULL
pointer.

Fixes: e8c92ed76900 ("GFS2: Clean up log write code path")
Signed-off-by: Jiasheng Jiang <[email protected]>
---
fs/gfs2/log.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index f0ee3ff6f9a8..10dd09e9b0e4 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -837,6 +837,9 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
return;

page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
+ if (!page)
+ return;
+
lh = page_address(page);
clear_page(lh);

--
2.25.1


2022-03-31 03:56:35

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [Cluster-devel] [PATCH] gfs2: Add check for mempool_alloc

On Fri, Mar 11, 2022 at 04:36:16PM +0800, Jiasheng Jiang wrote:
> As the potential failure of mempool_alloc(),
> it could return NULL pointer.
> Therefore, it should be better to check it
> in order to avoid the dereference of the NULL
> pointer.
>
> Fixes: e8c92ed76900 ("GFS2: Clean up log write code path")
> Signed-off-by: Jiasheng Jiang <[email protected]>

Please explain how it could fail to start with.