public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Vasyl Gomonovych <gomonovych@gmail.com>, mingo@kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] VMCI:  Use memdup_user() as a cleanup
Date: Wed, 22 Nov 2017 07:55:41 -0800	[thread overview]
Message-ID: <1511366141.6989.89.camel@perches.com> (raw)
In-Reply-To: <1511364547-18418-1-git-send-email-gomonovych@gmail.com>

On Wed, 2017-11-22 at 16:29 +0100, Vasyl Gomonovych wrote:
> Fix coccicheck warning which recommends to use memdup_user():
> drivers/misc/vmw_vmci/vmci_host.c:757:11-18: WARNING opportunity for memdup_user
> Generated by: scripts/coccinelle/memdup_user/memdup_user.cocci

Nice little cleanup.

> diff --git a/drivers/misc/vmw_vmci/vmci_host.c b/drivers/misc/vmw_vmci/vmci_host.c
[]
> @@ -754,18 +754,12 @@ static int vmci_host_do_ctx_set_cpt_state(struct vmci_host_dev *vmci_host_dev,
[]
> +	cpt_buf = memdup_user((void __user *)(uintptr_t)set_info.cpt_buf,
> +			set_info.buf_size);
> +	if (IS_ERR(cpt_buf)) {
> +		vmci_ioctl_err("cannot allocate memory to set cpt state (type=%d)\n",
> +				set_info.cpt_type);
> +		return PTR_ERR(cpt_buf);

Trivia:

The vmci_ioctl_err might not be necessary.
There is a dump_stack() on allocation failure.

and

> @@ -774,7 +768,6 @@ static int vmci_host_do_ctx_set_cpt_state(struct vmci_host_dev *vmci_host_dev,
>  
>  	retval = copy_to_user(uptr, &set_info, sizeof(set_info)) ? -EFAULT : 0;
>  
> -out:
>  	kfree(cpt_buf);
>  	return retval;

Perhaps move the kfree above the copy_to_user,
remove the retval declaration and use

	return copy_to_user(uptr, &set_info, sizeof(set_info)) ? -EFAULT : 0;

  reply	other threads:[~2017-11-22 15:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-22 15:29 [PATCH] VMCI: Use memdup_user() as a cleanup Vasyl Gomonovych
2017-11-22 15:55 ` Joe Perches [this message]
2017-11-22 20:46   ` Gomonovych, Vasyl
2017-11-22 22:42 ` [PATCH v2] " Vasyl Gomonovych

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=1511366141.6989.89.camel@perches.com \
    --to=joe@perches.com \
    --cc=gomonovych@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox