mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Bjørn Mork" <bjorn@mork.no>
To: Geliang Tang <geliangtang@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Oliver Neukum <oneukum@suse.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: cdc-wdm: use memdup_user
Date: Sat, 06 May 2017 19:40:42 +0200	[thread overview]
Message-ID: <87vapddgth.fsf@miraculix.mork.no> (raw)
In-Reply-To: <fad7dc9e4c665d3f31bca0de00c81434b74c3427.1493782228.git.geliangtang@gmail.com> (Geliang Tang's message of "Sat, 6 May 2017 23:42:18 +0800")

Geliang Tang <geliangtang@gmail.com> writes:

> Use memdup_user() helper instead of open-coding to simplify the code.
>
> Signed-off-by: Geliang Tang <geliangtang@gmail.com>
> ---
>  drivers/usb/class/cdc-wdm.c | 15 +++------------
>  1 file changed, 3 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
> index 08669fe..0e4f18c 100644
> --- a/drivers/usb/class/cdc-wdm.c
> +++ b/drivers/usb/class/cdc-wdm.c
> @@ -361,17 +361,9 @@ static ssize_t wdm_write
>  	if (we < 0)
>  		return usb_translate_errors(we);
>  
> -	buf = kmalloc(count, GFP_KERNEL);
> -	if (!buf) {
> -		rv = -ENOMEM;
> -		goto outnl;
> -	}
> -
> -	r = copy_from_user(buf, buffer, count);
> -	if (r > 0) {
> -		rv = -EFAULT;
> -		goto out_free_mem;
> -	}
> +	buf = memdup_user(buffer, count);
> +	if (IS_ERR(buf))
> +		return PTR_ERR(buf);
>  
>  	/* concurrent writes and disconnect */
>  	r = mutex_lock_interruptible(&desc->wlock);
> @@ -441,7 +433,6 @@ static ssize_t wdm_write
>  
>  	usb_autopm_put_interface(desc->intf);
>  	mutex_unlock(&desc->wlock);
> -outnl:
>  	return rv < 0 ? rv : count;
>  
>  out_free_mem_pm:

Nice!

Please check this, but I believe you can simplify that last return as
well. There is no way to end up there with rv < 0 after you've removed
the label. So

  return count;

should do.


Bjørn

  reply	other threads:[~2017-05-06 17:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-06 15:42 [PATCH] agp: " Geliang Tang
2017-05-06 15:42 ` [PATCH] net/hippi/rrunner: " Geliang Tang
2017-05-08 19:02   ` David Miller
2017-05-06 15:42 ` [PATCH] spi: spidev: " Geliang Tang
2017-05-08  9:28   ` Geert Uytterhoeven
2017-05-15  8:05   ` Applied "spi: spidev: use memdup_user" to the spi tree Mark Brown
2017-05-06 15:42 ` [PATCH] usb: cdc-wdm: use memdup_user Geliang Tang
2017-05-06 17:40   ` Bjørn Mork [this message]
2017-05-08 15:14     ` [PATCH v2] " Geliang Tang
2017-05-09  7:50       ` Oliver Neukum
2017-05-06 15:42 ` [PATCH] wil6210: " Geliang Tang
2017-05-19  7:55   ` Kalle Valo
2017-05-06 15:42 ` [PATCH] wlcore: " Geliang Tang
2017-05-18 13:41   ` Kalle Valo
2017-05-06 15:42 ` [PATCH] xfrm: " Geliang Tang
2017-05-16  9:30   ` Steffen Klassert
2017-05-06 15:42 ` [PATCH] yam: " Geliang Tang
2017-05-08 19:02   ` David Miller

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=87vapddgth.fsf@miraculix.mork.no \
    --to=bjorn@mork.no \
    --cc=geliangtang@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=oneukum@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®