Patchwork JFFS2: NULL return of kmem_cache_zalloc should be handled.

login
register
mail settings
Submitter Zhouyi Zhou
Date Dec. 2, 2013, 10:37 a.m.
Message ID <1385980625-26545-1-git-send-email-yizhouzhou@ict.ac.cn>
Download mbox | patch
Permalink /patch/295866/
State New
Headers show

Comments

Zhouyi Zhou - Dec. 2, 2013, 10:37 a.m.
NULL return of kmem_cache_zalloc should be handled in jffs2_alloc_xattr_datum
and jff2_alloc_xattr_ref.

Signed-off-by: Zhouyi Zhou <yizhouzhou@ict.ac.cn>
---
 fs/jffs2/malloc.c |    4 ++++
 1 file changed, 4 insertions(+)
Brian Norris - Dec. 9, 2013, 7:51 p.m.
On Mon, Dec 02, 2013 at 06:37:05PM +0800, Zhouyi Zhou wrote:
> NULL return of kmem_cache_zalloc should be handled in jffs2_alloc_xattr_datum
> and jff2_alloc_xattr_ref.
> 
> Signed-off-by: Zhouyi Zhou <yizhouzhou@ict.ac.cn>

Pushed to l2-mtd.git. Thanks!

Brian

Patch

diff --git a/fs/jffs2/malloc.c b/fs/jffs2/malloc.c
index 4f47aa2..b8fd651 100644
--- a/fs/jffs2/malloc.c
+++ b/fs/jffs2/malloc.c
@@ -288,6 +288,8 @@  struct jffs2_xattr_datum *jffs2_alloc_xattr_datum(void)
 	struct jffs2_xattr_datum *xd;
 	xd = kmem_cache_zalloc(xattr_datum_cache, GFP_KERNEL);
 	dbg_memalloc("%p\n", xd);
+	if (!xd)
+		return NULL;
 
 	xd->class = RAWNODE_CLASS_XATTR_DATUM;
 	xd->node = (void *)xd;
@@ -306,6 +308,8 @@  struct jffs2_xattr_ref *jffs2_alloc_xattr_ref(void)
 	struct jffs2_xattr_ref *ref;
 	ref = kmem_cache_zalloc(xattr_ref_cache, GFP_KERNEL);
 	dbg_memalloc("%p\n", ref);
+	if (!ref)
+		return NULL;
 
 	ref->class = RAWNODE_CLASS_XATTR_REF;
 	ref->node = (void *)ref;