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


Groups > linux.kernel > #1640860

Re: [PATCH] usb: gadget: f_fs: use memdup_user

From Dan Carpenter <dan.carpenter@oracle.com>
Newsgroups linux.kernel
Subject Re: [PATCH] usb: gadget: f_fs: use memdup_user
Date 2017-05-13 10:10 +0200
Message-ID <tGAhH-TJ-5@gated-at.bofh.it> (permalink)
References <tGvL4-6mY-7@gated-at.bofh.it> <tGvL4-6mY-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sat, May 13, 2017 at 11:15:59AM +0800, Geliang Tang wrote:
> Use memdup_user() helper instead of open-coding to simplify the code.
> 
> Signed-off-by: Geliang Tang <geliangtang@gmail.com>
> ---
>  drivers/usb/gadget/function/f_fs.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 71dd27c..5754538 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -3692,14 +3692,9 @@ static char *ffs_prepare_buffer(const char __user *buf, size_t len)
>  	if (unlikely(!len))
>  		return NULL;
>  
> -	data = kmalloc(len, GFP_KERNEL);
> -	if (unlikely(!data))
> -		return ERR_PTR(-ENOMEM);
> -
> -	if (unlikely(copy_from_user(data, buf, len))) {
> -		kfree(data);
> -		return ERR_PTR(-EFAULT);
> -	}
> +	data = memdup_user(buf, len);
> +	if (unlikely(IS_ERR(data)))

Don't use likely/unlikely() here.  It's not a fast path.

regards,
dan carpenter

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] KEYS: use memdup_user Geliang Tang <geliangtang@gmail.com> - 2017-05-13 05:20 +0200
  [PATCH] usb: gadget: f_fs: use memdup_user Geliang Tang <geliangtang@gmail.com> - 2017-05-13 05:20 +0200
    Re: [PATCH] usb: gadget: f_fs: use memdup_user Dan Carpenter <dan.carpenter@oracle.com> - 2017-05-13 10:10 +0200
      Re: [PATCH] usb: gadget: f_fs: use memdup_user Al Viro <viro@ZenIV.linux.org.uk> - 2017-05-21 05:30 +0200
    Re: [PATCH] usb: gadget: f_fs: use memdup_user Michal Nazarewicz <mina86@mina86.com> - 2017-05-14 13:40 +0200

csiph-web