linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] USB: gadget: f_fs: Use memdup_user() as a cleanup
@ 2021-03-25  3:48 Jay Fang
  2021-03-26 13:41 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Jay Fang @ 2021-03-25  3:48 UTC (permalink / raw)
  To: balbi, greg; +Cc: linux-usb, tangzihao1, huangdaode

From: Zihao Tang <tangzihao1@hisilicon.com>

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@intel.com>
Signed-off-by: Zihao Tang <tangzihao1@hisilicon.com>
Signed-off-by: Jay Fang <f.fangjian@huawei.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 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH V2] USB: gadget: f_fs: Use memdup_user() as a cleanup
  2021-03-25  3:48 [PATCH V2] USB: gadget: f_fs: Use memdup_user() as a cleanup Jay Fang
@ 2021-03-26 13:41 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2021-03-26 13:41 UTC (permalink / raw)
  To: Jay Fang; +Cc: balbi, linux-usb, tangzihao1, huangdaode

On Thu, Mar 25, 2021 at 11:48:20AM +0800, Jay Fang wrote:
> From: Zihao Tang <tangzihao1@hisilicon.com>
> 
> 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@intel.com>
> Signed-off-by: Zihao Tang <tangzihao1@hisilicon.com>
> Signed-off-by: Jay Fang <f.fangjian@huawei.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 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 :(

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-26 13:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-25  3:48 [PATCH V2] USB: gadget: f_fs: Use memdup_user() as a cleanup Jay Fang
2021-03-26 13:41 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).