mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: devel@linuxdriverproject.org
Cc: "K. Y. Srinivasan" <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	linux-kernel@vger.kernel.org, Olaf Hering <olaf@aepfle.de>,
	Dan Carpenter <dan.carpenter@oracle.com>
Subject: [PATCH v2 1/4] Drivers: hv: utils: fix memory leak on on_msg() failure
Date: Wed, 18 Nov 2015 14:40:48 +0100	[thread overview]
Message-ID: <1447854051-5570-2-git-send-email-vkuznets@redhat.com> (raw)
In-Reply-To: <1447854051-5570-1-git-send-email-vkuznets@redhat.com>

inmsg should be freed in case of on_msg() failure to avoid memory leak.
Preserve the error code from on_msg().

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
Changes since v1:
- Preserve the error code from on_msg(). [Dan Carpenter]
---
 drivers/hv/hv_utils_transport.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/hv/hv_utils_transport.c b/drivers/hv/hv_utils_transport.c
index 24b2766..40abe44 100644
--- a/drivers/hv/hv_utils_transport.c
+++ b/drivers/hv/hv_utils_transport.c
@@ -77,6 +77,7 @@ static ssize_t hvt_op_write(struct file *file, const char __user *buf,
 {
 	struct hvutil_transport *hvt;
 	u8 *inmsg;
+	int ret;
 
 	hvt = container_of(file->f_op, struct hvutil_transport, fops);
 
@@ -84,11 +85,11 @@ static ssize_t hvt_op_write(struct file *file, const char __user *buf,
 	if (IS_ERR(inmsg))
 		return PTR_ERR(inmsg);
 
-	if (hvt->on_msg(inmsg, count))
-		return -EFAULT;
+	ret = hvt->on_msg(inmsg, count);
+
 	kfree(inmsg);
 
-	return count;
+	return ret ? ret : count;
 }
 
 static unsigned int hvt_op_poll(struct file *file, poll_table *wait)
-- 
2.4.3


  reply	other threads:[~2015-11-18 13:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-18 13:40 [PATCH v2 0/4] Drivers: hv: utils: prevent crash when a utility driver is disabled host side Vitaly Kuznetsov
2015-11-18 13:40 ` Vitaly Kuznetsov [this message]
2015-11-18 13:40 ` [PATCH v2 2/4] Drivers: hv: utils: rename outmsg_lock Vitaly Kuznetsov
2015-11-18 13:40 ` [PATCH v2 3/4] Drivers: hv: utils: introduce HVUTIL_TRANSPORT_DESTROY mode Vitaly Kuznetsov
2015-11-18 13:40 ` [PATCH v2 4/4] Drivers: hv: utils: fix crash when device is removed from host side Vitaly Kuznetsov

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=1447854051-5570-2-git-send-email-vkuznets@redhat.com \
    --to=vkuznets@redhat.com \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@linuxdriverproject.org \
    --cc=haiyangz@microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olaf@aepfle.de \
    /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®