Skip to content

Commit

Permalink
drm/vmwgfx: Fix host logging / guestinfo reading error paths
Browse files Browse the repository at this point in the history
The error paths were leaking opened channels.
Fix by using dedicated error paths.

Cc: <stable@vger.kernel.org>
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Sinclair Yeh <syeh@vmware.com>
  • Loading branch information
Thomas Hellstrom committed May 23, 2018
1 parent 938ae72 commit f37230c
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,6 @@ int vmw_host_get_guestinfo(const char *guest_info_param,
struct rpc_channel channel;
char *msg, *reply = NULL;
size_t reply_len = 0;
int ret = 0;


if (!vmw_msg_enabled)
return -ENODEV;
Expand All @@ -344,15 +342,14 @@ int vmw_host_get_guestinfo(const char *guest_info_param,
return -ENOMEM;
}

if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM) ||
vmw_send_msg(&channel, msg) ||
vmw_recv_msg(&channel, (void *) &reply, &reply_len) ||
vmw_close_channel(&channel)) {
DRM_ERROR("Failed to get %s", guest_info_param);
if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM))
goto out_open;

ret = -EINVAL;
}
if (vmw_send_msg(&channel, msg) ||
vmw_recv_msg(&channel, (void *) &reply, &reply_len))
goto out_msg;

vmw_close_channel(&channel);
if (buffer && reply && reply_len > 0) {
/* Remove reply code, which are the first 2 characters of
* the reply
Expand All @@ -369,7 +366,17 @@ int vmw_host_get_guestinfo(const char *guest_info_param,
kfree(reply);
kfree(msg);

return ret;
return 0;

out_msg:
vmw_close_channel(&channel);
kfree(reply);
out_open:
*length = 0;
kfree(msg);
DRM_ERROR("Failed to get %s", guest_info_param);

return -EINVAL;
}


Expand Down Expand Up @@ -400,15 +407,22 @@ int vmw_host_log(const char *log)
return -ENOMEM;
}

if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM) ||
vmw_send_msg(&channel, msg) ||
vmw_close_channel(&channel)) {
DRM_ERROR("Failed to send log\n");
if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM))
goto out_open;

ret = -EINVAL;
}
if (vmw_send_msg(&channel, msg))
goto out_msg;

vmw_close_channel(&channel);
kfree(msg);

return ret;
return 0;

out_msg:
vmw_close_channel(&channel);
out_open:
kfree(msg);
DRM_ERROR("Failed to send log\n");

return -EINVAL;
}

0 comments on commit f37230c

Please sign in to comment.