lkml.org 
[lkml]   [2017]   [May]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] usb: cdc-wdm: use memdup_user
Date
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

\
 
 \ /
  Last update: 2017-05-06 19:41    [W:0.117 / U:0.592 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site