public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] NFS: check for allocation failure from mempool_alloc
@ 2020-02-26 23:43 Colin King
  2020-02-26 23:48 ` Trond Myklebust
  2020-03-02  7:30 ` Dan Carpenter
  0 siblings, 2 replies; 4+ messages in thread
From: Colin King @ 2020-02-26 23:43 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker, linux-nfs; +Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

It is possible for mempool_alloc to return null when using
the GFP_KERNEL flag, so return NULL and avoid a null pointer
dereference on the following memset of the null pointer.

Addresses-Coverity: ("Dereference null return")
Fixes: 2b17d725f9be ("NFS: Clean up writeback code")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 fs/nfs/write.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index c478b772cc49..7ca036660dd1 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -106,6 +106,9 @@ static struct nfs_pgio_header *nfs_writehdr_alloc(void)
 {
 	struct nfs_pgio_header *p = mempool_alloc(nfs_wdata_mempool, GFP_KERNEL);
 
+	if (!p)
+		return NULL;
+
 	memset(p, 0, sizeof(*p));
 	p->rw_mode = FMODE_WRITE;
 	return p;
-- 
2.25.0


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

end of thread, other threads:[~2020-03-02  7:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-26 23:43 [PATCH] NFS: check for allocation failure from mempool_alloc Colin King
2020-02-26 23:48 ` Trond Myklebust
2020-02-26 23:56   ` Colin Ian King
2020-03-02  7:30 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox