Re: [PATCH V2] USB: gadget: f_fs: Use memdup_user() as a cleanup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 25, 2021 at 11:48:20AM +0800, Jay Fang wrote:
> From: Zihao Tang <tangzihao1@xxxxxxxxxxxxx>
> 
> Fix coccicheck warning which recommends to use memdup_user():
> 
> drivers/usb/gadget/function/f_fs.c:3829:8-15: WARNING opportunity for memdup_user
> 
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
> Signed-off-by: Zihao Tang <tangzihao1@xxxxxxxxxxxxx>
> Signed-off-by: Jay Fang <f.fangjian@xxxxxxxxxx>
> ---
>  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 801a8b6..90a24d4 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -3826,14 +3826,9 @@ static char *ffs_prepare_buffer(const char __user *buf, size_t len)
>  	if (!len)
>  		return NULL;
>  
> -	data = kmalloc(len, GFP_KERNEL);
> -	if (!data)
> -		return ERR_PTR(-ENOMEM);
> -
> -	if (copy_from_user(data, buf, len)) {
> -		kfree(data);
> -		return ERR_PTR(-EFAULT);
> -	}
> +	data = memdup_user(buf, len);
> +	if (IS_ERR(data))
> +		return data;
>  
>  	pr_vdebug("Buffer from user space:\n");
>  	ffs_dump_mem("", data, len);
> -- 
> 2.7.4
> 

Does not apply to my tree at all :(



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux