lkml.org 
[lkml]   [2019]   [Jan]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] virtio:linux:kernel:NULL check after kmalloc is needed
Date
From: "huang.zijiang" <huang.zijiang@zte.com.cn>

NULL check is needed because kmalloc maybe return NULL.

Signed-off-by: huang.zijiang <huang.zijiang@zte.com.cn>
---
tools/virtio/linux/kernel.h | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/virtio/linux/kernel.h b/tools/virtio/linux/kernel.h
index 7ef45a4..2afcad8 100644
--- a/tools/virtio/linux/kernel.h
+++ b/tools/virtio/linux/kernel.h
@@ -65,6 +65,8 @@ static inline void *kzalloc(size_t s, gfp_t gfp)
{
void *p = kmalloc(s, gfp);

+ if (!p)
+ return -ENOMEM;
memset(p, 0, s);
return p;
}
--
1.8.3.1
\
 
 \ /
  Last update: 2019-01-08 06:42    [W:0.045 / U:0.664 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site