mirror of https://gitee.com/openkylin/linux.git
drm/vmwgfx: Use kasprintf
Use kasprintf instead of combination of kmalloc and sprintf. Also, remove the local variables used for storing the string length as they are not required now. Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com> Reviewed-by: Sinclair Yeh <syeh@vmware.com> Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
This commit is contained in:
parent
4e3e733b45
commit
6073a09210
|
@ -328,7 +328,7 @@ int vmw_host_get_guestinfo(const char *guest_info_param,
|
||||||
{
|
{
|
||||||
struct rpc_channel channel;
|
struct rpc_channel channel;
|
||||||
char *msg, *reply = NULL;
|
char *msg, *reply = NULL;
|
||||||
size_t msg_len, reply_len = 0;
|
size_t reply_len = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
|
||||||
|
@ -338,15 +338,12 @@ int vmw_host_get_guestinfo(const char *guest_info_param,
|
||||||
if (!guest_info_param || !length)
|
if (!guest_info_param || !length)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
msg_len = strlen(guest_info_param) + strlen("info-get ") + 1;
|
msg = kasprintf(GFP_KERNEL, "info-get %s", guest_info_param);
|
||||||
msg = kzalloc(msg_len, GFP_KERNEL);
|
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
DRM_ERROR("Cannot allocate memory to get %s", guest_info_param);
|
DRM_ERROR("Cannot allocate memory to get %s", guest_info_param);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(msg, "info-get %s", guest_info_param);
|
|
||||||
|
|
||||||
if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM) ||
|
if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM) ||
|
||||||
vmw_send_msg(&channel, msg) ||
|
vmw_send_msg(&channel, msg) ||
|
||||||
vmw_recv_msg(&channel, (void *) &reply, &reply_len) ||
|
vmw_recv_msg(&channel, (void *) &reply, &reply_len) ||
|
||||||
|
@ -388,7 +385,6 @@ int vmw_host_log(const char *log)
|
||||||
{
|
{
|
||||||
struct rpc_channel channel;
|
struct rpc_channel channel;
|
||||||
char *msg;
|
char *msg;
|
||||||
int msg_len;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
|
||||||
|
@ -398,15 +394,12 @@ int vmw_host_log(const char *log)
|
||||||
if (!log)
|
if (!log)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
msg_len = strlen(log) + strlen("log ") + 1;
|
msg = kasprintf(GFP_KERNEL, "log %s", log);
|
||||||
msg = kzalloc(msg_len, GFP_KERNEL);
|
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
DRM_ERROR("Cannot allocate memory for log message\n");
|
DRM_ERROR("Cannot allocate memory for log message\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(msg, "log %s", log);
|
|
||||||
|
|
||||||
if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM) ||
|
if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM) ||
|
||||||
vmw_send_msg(&channel, msg) ||
|
vmw_send_msg(&channel, msg) ||
|
||||||
vmw_close_channel(&channel)) {
|
vmw_close_channel(&channel)) {
|
||||||
|
|
Loading…
Reference in New Issue