[v2,for-4.4,08/16] Drivers: hv: don't leak memory in vmbus_establish_gpadl()

Message ID 1492019030-13567-9-git-send-email-sumit.semwal@linaro.org
State New
Headers show
Series
  • Stable commits from Ubuntu Xenial 4.4-lts
Related show

Commit Message

Sumit Semwal April 12, 2017, 5:43 p.m.
From: Vitaly Kuznetsov <vkuznets@redhat.com>


[ Upstream commit 7cc80c98070ccc7940fc28811c92cca0a681015d ]

In some cases create_gpadl_header() allocates submessages but we never
free them.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>

Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>

---
 drivers/hv/channel.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

-- 
2.7.4

Patch

diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index fb1e3df..ec61ad8 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -373,7 +373,7 @@  int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
 	struct vmbus_channel_gpadl_header *gpadlmsg;
 	struct vmbus_channel_gpadl_body *gpadl_body;
 	struct vmbus_channel_msginfo *msginfo = NULL;
-	struct vmbus_channel_msginfo *submsginfo;
+	struct vmbus_channel_msginfo *submsginfo, *tmp;
 	struct list_head *curr;
 	u32 next_gpadl_handle;
 	unsigned long flags;
@@ -430,6 +430,10 @@  cleanup:
 	spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
 	list_del(&msginfo->msglistentry);
 	spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
+	list_for_each_entry_safe(submsginfo, tmp, &msginfo->submsglist,
+				 msglistentry) {
+		kfree(submsginfo);
+	}
 
 	kfree(msginfo);
 	return ret;