mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hv: util: catch allocation errors
@ 2015-09-30  9:05 Olaf Hering
  2015-09-30  9:25 ` [PATCH] hv: util: fix memdup_user.cocci warnings kbuild test robot
  2015-09-30  9:25 ` [PATCH] hv: util: catch allocation errors kbuild test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Olaf Hering @ 2015-09-30  9:05 UTC (permalink / raw)
  To: kys, haiyangz; +Cc: linux-kernel, Olaf Hering

Catch allocation errors in hvt_op_write and hvutil_transport_send.

Fixes: 14b50f80c32d ('Drivers: hv: util: introduce hv_utils_transport abstraction')

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 drivers/hv/hv_utils_transport.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/hv/hv_utils_transport.c b/drivers/hv/hv_utils_transport.c
index 6a9d80a..13af065 100644
--- a/drivers/hv/hv_utils_transport.c
+++ b/drivers/hv/hv_utils_transport.c
@@ -81,6 +81,8 @@ static ssize_t hvt_op_write(struct file *file, const char __user *buf,
 	hvt = container_of(file->f_op, struct hvutil_transport, fops);
 
 	inmsg = kzalloc(count, GFP_KERNEL);
+	if (!inmsg)
+		return -ENOMEM;
 	if (copy_from_user(inmsg, buf, count)) {
 		kfree(inmsg);
 		return -EFAULT;
@@ -204,9 +206,12 @@ int hvutil_transport_send(struct hvutil_transport *hvt, void *msg, int len)
 		goto out_unlock;
 	}
 	hvt->outmsg = kzalloc(len, GFP_KERNEL);
-	memcpy(hvt->outmsg, msg, len);
-	hvt->outmsg_len = len;
-	wake_up_interruptible(&hvt->outmsg_q);
+	if (hvt->outmsg) {
+		memcpy(hvt->outmsg, msg, len);
+		hvt->outmsg_len = len;
+		wake_up_interruptible(&hvt->outmsg_q);
+	} else
+		ret = -ENOMEM;
 out_unlock:
 	mutex_unlock(&hvt->outmsg_lock);
 	return ret;

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

end of thread, other threads:[~2015-09-30  9:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-30  9:05 [PATCH] hv: util: catch allocation errors Olaf Hering
2015-09-30  9:25 ` [PATCH] hv: util: fix memdup_user.cocci warnings kbuild test robot
2015-09-30  9:25 ` [PATCH] hv: util: catch allocation errors kbuild test robot

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®