From: Hank Janssen <hjanssen@microsoft.com>
To: hjanssen@microsoft.com, zbr@ioremap.net, gregkh@suse.de,
linux-kernel@vger.kernel.org, devel@linuxdriverproject.org,
virtualization@lists.osdl.org
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Subject: [PATCH 1/1] Properly check return values of kmalloc and vmbus_recvpacket
Date: Thu, 9 Dec 2010 12:23:29 -0800 [thread overview]
Message-ID: <1291926209-17120-1-git-send-email-hjanssen@microsoft.com> (raw)
Correct ugly oversight, we need to check the return values of kmalloc
and vmbus_recvpacket and return if they fail. I also tightened up the
call to kmalloc.
Thanks to Evgeniy Polyakov <zbr@ioremap.net> for pointing this out.
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Hank Janssen <hjanssen@microsoft.com>
---
drivers/staging/hv/hv_utils.c | 48 ++++++++++++++++++++++++++++------------
1 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/drivers/staging/hv/hv_utils.c b/drivers/staging/hv/hv_utils.c
index 53e1e29..ac68575 100644
--- a/drivers/staging/hv/hv_utils.c
+++ b/drivers/staging/hv/hv_utils.c
@@ -43,21 +43,27 @@ static void shutdown_onchannelcallback(void *context)
{
struct vmbus_channel *channel = context;
u8 *buf;
- u32 buflen, recvlen;
+ u32 recvlen;
u64 requestid;
u8 execute_shutdown = false;
+ int ret = 0;
struct shutdown_msg_data *shutdown_msg;
struct icmsg_hdr *icmsghdrp;
struct icmsg_negotiate *negop = NULL;
- buflen = PAGE_SIZE;
- buf = kmalloc(buflen, GFP_ATOMIC);
+ buf = kmalloc(PAGE_SIZE, GFP_ATOMIC);
- vmbus_recvpacket(channel, buf, buflen, &recvlen, &requestid);
+ if (!buf) {
+ printk(KERN_INFO
+ "Unable to allocate memory for shutdown_onchannelcallback");
+ return;
+ }
+
+ ret = vmbus_recvpacket(channel, buf, PAGE_SIZE, &recvlen, &requestid);
- if (recvlen > 0) {
+ if (ret == 0 && recvlen > 0) {
DPRINT_DBG(VMBUS, "shutdown packet: len=%d, requestid=%lld",
recvlen, requestid);
@@ -151,17 +157,23 @@ static void timesync_onchannelcallback(void *context)
{
struct vmbus_channel *channel = context;
u8 *buf;
- u32 buflen, recvlen;
+ u32 recvlen;
u64 requestid;
struct icmsg_hdr *icmsghdrp;
struct ictimesync_data *timedatap;
+ int ret = 0;
- buflen = PAGE_SIZE;
- buf = kmalloc(buflen, GFP_ATOMIC);
+ buf = kmalloc(PAGE_SIZE, GFP_ATOMIC);
- vmbus_recvpacket(channel, buf, buflen, &recvlen, &requestid);
+ if (!buf) {
+ printk(KERN_INFO
+ "Unable to allocate memory for timesync_onchannelcallback");
+ return;
+ }
- if (recvlen > 0) {
+ ret = vmbus_recvpacket(channel, buf, PAGE_SIZE, &recvlen, &requestid);
+
+ if (ret == 0 && recvlen > 0) {
DPRINT_DBG(VMBUS, "timesync packet: recvlen=%d, requestid=%lld",
recvlen, requestid);
@@ -197,17 +209,23 @@ static void heartbeat_onchannelcallback(void *context)
{
struct vmbus_channel *channel = context;
u8 *buf;
- u32 buflen, recvlen;
+ u32 recvlen;
u64 requestid;
struct icmsg_hdr *icmsghdrp;
struct heartbeat_msg_data *heartbeat_msg;
+ int ret = 0;
+
+ buf = kmalloc(PAGE_SIZE, GFP_ATOMIC);
- buflen = PAGE_SIZE;
- buf = kmalloc(buflen, GFP_ATOMIC);
+ if (!buf) {
+ printk(KERN_INFO
+ "Unable to allocate memory for heartbeat_onchannelcallback");
+ return;
+ }
- vmbus_recvpacket(channel, buf, buflen, &recvlen, &requestid);
+ ret = vmbus_recvpacket(channel, buf, PAGE_SIZE, &recvlen, &requestid);
- if (recvlen > 0) {
+ if (ret == 0 && recvlen > 0) {
DPRINT_DBG(VMBUS, "heartbeat packet: len=%d, requestid=%lld",
recvlen, requestid);
--
1.6.0.2
next reply other threads:[~2010-12-09 20:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-09 20:23 Hank Janssen [this message]
2010-12-10 0:13 ` [PATCH 1/1] Properly check return values of kmalloc and vmbus_recvpacket Ky Srinivasan
2010-12-10 0:10 ` Jesper Juhl
2010-12-10 0:20 ` Hank Janssen
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=1291926209-17120-1-git-send-email-hjanssen@microsoft.com \
--to=hjanssen@microsoft.com \
--cc=devel@linuxdriverproject.org \
--cc=gregkh@suse.de \
--cc=haiyangz@microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=virtualization@lists.osdl.org \
--cc=zbr@ioremap.net \
/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