Commit 13925502 authored by K. Y. Srinivasan's avatar K. Y. Srinivasan Committed by Greg Kroah-Hartman

Drivers: hv: Cleanup error handling in vmbus_open()

Fix a memory leak  in the error handling path in the function vmbus_open().
Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
Reviewed-by: default avatarHaiyang Zhang <haiyangz@microsoft.com>
Reported-by: default avatarJason Wang <jasowang@redhat.com>
Cc: Stable <stable@vger.kernel.org>
Acked-by: default avatarJason Wang <jasowang@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 1b207734
...@@ -146,14 +146,14 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, ...@@ -146,14 +146,14 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
if (ret != 0) { if (ret != 0) {
err = ret; err = ret;
goto errorout; goto error0;
} }
ret = hv_ringbuffer_init( ret = hv_ringbuffer_init(
&newchannel->inbound, in, recv_ringbuffer_size); &newchannel->inbound, in, recv_ringbuffer_size);
if (ret != 0) { if (ret != 0) {
err = ret; err = ret;
goto errorout; goto error0;
} }
...@@ -168,7 +168,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, ...@@ -168,7 +168,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
if (ret != 0) { if (ret != 0) {
err = ret; err = ret;
goto errorout; goto error0;
} }
/* Create and init the channel open message */ /* Create and init the channel open message */
...@@ -177,7 +177,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, ...@@ -177,7 +177,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
GFP_KERNEL); GFP_KERNEL);
if (!open_info) { if (!open_info) {
err = -ENOMEM; err = -ENOMEM;
goto errorout; goto error0;
} }
init_completion(&open_info->waitevent); init_completion(&open_info->waitevent);
...@@ -193,7 +193,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, ...@@ -193,7 +193,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
if (userdatalen > MAX_USER_DEFINED_BYTES) { if (userdatalen > MAX_USER_DEFINED_BYTES) {
err = -EINVAL; err = -EINVAL;
goto errorout; goto error0;
} }
if (userdatalen) if (userdatalen)
...@@ -208,19 +208,18 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, ...@@ -208,19 +208,18 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
sizeof(struct vmbus_channel_open_channel)); sizeof(struct vmbus_channel_open_channel));
if (ret != 0) if (ret != 0)
goto cleanup; goto error1;
t = wait_for_completion_timeout(&open_info->waitevent, 5*HZ); t = wait_for_completion_timeout(&open_info->waitevent, 5*HZ);
if (t == 0) { if (t == 0) {
err = -ETIMEDOUT; err = -ETIMEDOUT;
goto errorout; goto error1;
} }
if (open_info->response.open_result.status) if (open_info->response.open_result.status)
err = open_info->response.open_result.status; err = open_info->response.open_result.status;
cleanup:
spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
list_del(&open_info->msglistentry); list_del(&open_info->msglistentry);
spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
...@@ -228,9 +227,12 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, ...@@ -228,9 +227,12 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
kfree(open_info); kfree(open_info);
return err; return err;
errorout: error1:
hv_ringbuffer_cleanup(&newchannel->outbound); spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
hv_ringbuffer_cleanup(&newchannel->inbound); list_del(&open_info->msglistentry);
spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
error0:
free_pages((unsigned long)out, free_pages((unsigned long)out,
get_order(send_ringbuffer_size + recv_ringbuffer_size)); get_order(send_ringbuffer_size + recv_ringbuffer_size));
kfree(open_info); kfree(open_info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment