usb: cdc-wdm: use memdup_user

Use memdup_user() helper instead of open-coding to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Acked-by: Oliver Neukum <oneukum@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Geliang Tang 2017-05-08 23:14:39 +08:00 committed by Greg Kroah-Hartman
parent 2ea659a9ef
commit 64b9533ec1

View File

@ -361,17 +361,9 @@ static ssize_t wdm_write
if (we < 0) if (we < 0)
return usb_translate_errors(we); return usb_translate_errors(we);
buf = kmalloc(count, GFP_KERNEL); buf = memdup_user(buffer, count);
if (!buf) { if (IS_ERR(buf))
rv = -ENOMEM; return PTR_ERR(buf);
goto outnl;
}
r = copy_from_user(buf, buffer, count);
if (r > 0) {
rv = -EFAULT;
goto out_free_mem;
}
/* concurrent writes and disconnect */ /* concurrent writes and disconnect */
r = mutex_lock_interruptible(&desc->wlock); r = mutex_lock_interruptible(&desc->wlock);
@ -441,8 +433,7 @@ static ssize_t wdm_write
usb_autopm_put_interface(desc->intf); usb_autopm_put_interface(desc->intf);
mutex_unlock(&desc->wlock); mutex_unlock(&desc->wlock);
outnl: return count;
return rv < 0 ? rv : count;
out_free_mem_pm: out_free_mem_pm:
usb_autopm_put_interface(desc->intf); usb_autopm_put_interface(desc->intf);