All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sinclair Yeh <syeh@vmware.com>
To: Himanshu Jha <himanshujha199640@gmail.com>
Cc: airlied@linux.ie, thellstrom@vmware.com,
	linux-graphics-maintainer@vmware.com,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/vmwgfx: Use kasprintf
Date: Mon, 12 Mar 2018 11:52:59 -0700	[thread overview]
Message-ID: <20180312185258.GC32341@vmware.com> (raw)
In-Reply-To: <1520445802-11894-1-git-send-email-himanshujha199640@gmail.com>

Thanks!

Reviewed-by: Sinclair Yeh <syeh@vmware.com>

On Wed, Mar 07, 2018 at 11:33:22PM +0530, Himanshu Jha wrote:
> 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>
> ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 13 +++----------
>  1 file changed, 3 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
> index 9700099..cdff992 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
> @@ -328,7 +328,7 @@ int vmw_host_get_guestinfo(const char *guest_info_param,
>  {
>  	struct rpc_channel channel;
>  	char *msg, *reply = NULL;
> -	size_t msg_len, reply_len = 0;
> +	size_t reply_len = 0;
>  	int ret = 0;
>  
>  
> @@ -338,15 +338,12 @@ int vmw_host_get_guestinfo(const char *guest_info_param,
>  	if (!guest_info_param || !length)
>  		return -EINVAL;
>  
> -	msg_len = strlen(guest_info_param) + strlen("info-get ") + 1;
> -	msg = kzalloc(msg_len, GFP_KERNEL);
> +	msg = kasprintf(GFP_KERNEL, "info-get %s", guest_info_param);
>  	if (!msg) {
>  		DRM_ERROR("Cannot allocate memory to get %s", guest_info_param);
>  		return -ENOMEM;
>  	}
>  
> -	sprintf(msg, "info-get %s", guest_info_param);
> -
>  	if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM) ||
>  	    vmw_send_msg(&channel, msg) ||
>  	    vmw_recv_msg(&channel, (void *) &reply, &reply_len) ||
> @@ -388,7 +385,6 @@ int vmw_host_log(const char *log)
>  {
>  	struct rpc_channel channel;
>  	char *msg;
> -	int msg_len;
>  	int ret = 0;
>  
>  
> @@ -398,15 +394,12 @@ int vmw_host_log(const char *log)
>  	if (!log)
>  		return ret;
>  
> -	msg_len = strlen(log) + strlen("log ") + 1;
> -	msg = kzalloc(msg_len, GFP_KERNEL);
> +	msg = kasprintf(GFP_KERNEL, "log %s", log);
>  	if (!msg) {
>  		DRM_ERROR("Cannot allocate memory for log message\n");
>  		return -ENOMEM;
>  	}
>  
> -	sprintf(msg, "log %s", log);
> -
>  	if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM) ||
>  	    vmw_send_msg(&channel, msg) ||
>  	    vmw_close_channel(&channel)) {
> -- 
> 2.7.4
> 
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: Sinclair Yeh <syeh@vmware.com>
To: Himanshu Jha <himanshujha199640@gmail.com>
Cc: linux-graphics-maintainer@vmware.com, airlied@linux.ie,
	thellstrom@vmware.com, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/vmwgfx: Use kasprintf
Date: Mon, 12 Mar 2018 11:52:59 -0700	[thread overview]
Message-ID: <20180312185258.GC32341@vmware.com> (raw)
In-Reply-To: <1520445802-11894-1-git-send-email-himanshujha199640@gmail.com>

Thanks!

Reviewed-by: Sinclair Yeh <syeh@vmware.com>

On Wed, Mar 07, 2018 at 11:33:22PM +0530, Himanshu Jha wrote:
> 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>
> ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 13 +++----------
>  1 file changed, 3 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
> index 9700099..cdff992 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
> @@ -328,7 +328,7 @@ int vmw_host_get_guestinfo(const char *guest_info_param,
>  {
>  	struct rpc_channel channel;
>  	char *msg, *reply = NULL;
> -	size_t msg_len, reply_len = 0;
> +	size_t reply_len = 0;
>  	int ret = 0;
>  
>  
> @@ -338,15 +338,12 @@ int vmw_host_get_guestinfo(const char *guest_info_param,
>  	if (!guest_info_param || !length)
>  		return -EINVAL;
>  
> -	msg_len = strlen(guest_info_param) + strlen("info-get ") + 1;
> -	msg = kzalloc(msg_len, GFP_KERNEL);
> +	msg = kasprintf(GFP_KERNEL, "info-get %s", guest_info_param);
>  	if (!msg) {
>  		DRM_ERROR("Cannot allocate memory to get %s", guest_info_param);
>  		return -ENOMEM;
>  	}
>  
> -	sprintf(msg, "info-get %s", guest_info_param);
> -
>  	if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM) ||
>  	    vmw_send_msg(&channel, msg) ||
>  	    vmw_recv_msg(&channel, (void *) &reply, &reply_len) ||
> @@ -388,7 +385,6 @@ int vmw_host_log(const char *log)
>  {
>  	struct rpc_channel channel;
>  	char *msg;
> -	int msg_len;
>  	int ret = 0;
>  
>  
> @@ -398,15 +394,12 @@ int vmw_host_log(const char *log)
>  	if (!log)
>  		return ret;
>  
> -	msg_len = strlen(log) + strlen("log ") + 1;
> -	msg = kzalloc(msg_len, GFP_KERNEL);
> +	msg = kasprintf(GFP_KERNEL, "log %s", log);
>  	if (!msg) {
>  		DRM_ERROR("Cannot allocate memory for log message\n");
>  		return -ENOMEM;
>  	}
>  
> -	sprintf(msg, "log %s", log);
> -
>  	if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM) ||
>  	    vmw_send_msg(&channel, msg) ||
>  	    vmw_close_channel(&channel)) {
> -- 
> 2.7.4
> 

  reply	other threads:[~2018-03-12 18:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-07 18:03 [PATCH] drm/vmwgfx: Use kasprintf Himanshu Jha
2018-03-12 18:52 ` Sinclair Yeh [this message]
2018-03-12 18:52   ` Sinclair Yeh

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=20180312185258.GC32341@vmware.com \
    --to=syeh@vmware.com \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=himanshujha199640@gmail.com \
    --cc=linux-graphics-maintainer@vmware.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thellstrom@vmware.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.