From: Yi Wang <wang.yi59@zte.com.cn>
To: mst@redhat.com
Cc: jasowang@redhat.com, davem@davemloft.net,
virtualization@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, xue.zhihong@zte.com.cn,
wang.yi59@zte.com.cn, "huang.zijiang" <huang.zijiang@zte.com.cn>
Subject: [PATCH] virtio:linux:kernel:NULL check after kmalloc is needed
Date: Tue, 8 Jan 2019 13:40:33 +0800 [thread overview]
Message-ID: <1546926033-31684-1-git-send-email-wang.yi59@zte.com.cn> (raw)
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
next reply other threads:[~2019-01-08 5:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-08 5:40 Yi Wang [this message]
2019-01-09 14:30 ` Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1546926033-31684-1-git-send-email-wang.yi59@zte.com.cn \
--to=wang.yi59@zte.com.cn \
--cc=davem@davemloft.net \
--cc=huang.zijiang@zte.com.cn \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=xue.zhihong@zte.com.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®