Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1640830 > unrolled thread

[PATCH] USB: iowarrior: use memdup_user

Started byGeliang Tang <geliangtang@gmail.com>
First post2017-05-13 05:20 +0200
Last post2017-05-15 12:20 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH] USB: iowarrior: use memdup_user Geliang Tang <geliangtang@gmail.com> - 2017-05-13 05:20 +0200
    Re: [PATCH] USB: iowarrior: use memdup_user Johan Hovold <johan@kernel.org> - 2017-05-15 12:20 +0200

#1640830 — [PATCH] USB: iowarrior: use memdup_user

FromGeliang Tang <geliangtang@gmail.com>
Date2017-05-13 05:20 +0200
Subject[PATCH] USB: iowarrior: use memdup_user
Message-ID<tGvL4-6mY-9@gated-at.bofh.it>
Use memdup_user() helper instead of open-coding to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
 drivers/usb/misc/iowarrior.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index 7756953..816afad 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -368,14 +368,9 @@ static ssize_t iowarrior_write(struct file *file,
 	case USB_DEVICE_ID_CODEMERCS_IOWPV2:
 	case USB_DEVICE_ID_CODEMERCS_IOW40:
 		/* IOW24 and IOW40 use a synchronous call */
-		buf = kmalloc(count, GFP_KERNEL);
-		if (!buf) {
-			retval = -ENOMEM;
-			goto exit;
-		}
-		if (copy_from_user(buf, user_buffer, count)) {
-			retval = -EFAULT;
-			kfree(buf);
+		buf = memdup_user(user_buffer, count);
+		if (IS_ERR(buf)) {
+			retval = PTR_ERR(buf);
 			goto exit;
 		}
 		retval = usb_set_report(dev->interface, 2, 0, buf, count);
-- 
2.9.3

[toc] | [next] | [standalone]


#1641510

FromJohan Hovold <johan@kernel.org>
Date2017-05-15 12:20 +0200
Message-ID<tHlgB-6Pc-1@gated-at.bofh.it>
In reply to#1640830
On Sat, May 13, 2017 at 11:16:00AM +0800, Geliang Tang wrote:
> Use memdup_user() helper instead of open-coding to simplify the code.
> 
> Signed-off-by: Geliang Tang <geliangtang@gmail.com>

Looks good to me:

Reviewed-by: Johan Hovold <johan@kernel.org>

> ---
>  drivers/usb/misc/iowarrior.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
> index 7756953..816afad 100644
> --- a/drivers/usb/misc/iowarrior.c
> +++ b/drivers/usb/misc/iowarrior.c
> @@ -368,14 +368,9 @@ static ssize_t iowarrior_write(struct file *file,
>  	case USB_DEVICE_ID_CODEMERCS_IOWPV2:
>  	case USB_DEVICE_ID_CODEMERCS_IOW40:
>  		/* IOW24 and IOW40 use a synchronous call */
> -		buf = kmalloc(count, GFP_KERNEL);
> -		if (!buf) {
> -			retval = -ENOMEM;
> -			goto exit;
> -		}
> -		if (copy_from_user(buf, user_buffer, count)) {
> -			retval = -EFAULT;
> -			kfree(buf);
> +		buf = memdup_user(user_buffer, count);
> +		if (IS_ERR(buf)) {
> +			retval = PTR_ERR(buf);
>  			goto exit;
>  		}
>  		retval = usb_set_report(dev->interface, 2, 0, buf, count);

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web