Message ID | 1616145346-1410-1-git-send-email-f.fangjian@huawei.com |
---|---|
State | Superseded |
Headers | show |
Series | USB: gadget: f_fs: Use memdup_user() as a cleanup | expand |
On Fri, Mar 19, 2021 at 05:15:46PM +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 | 9 +-------- > 1 file changed, 1 insertion(+), 8 deletions(-) > > diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c > index 801a8b6..2f904f0 100644 > --- a/drivers/usb/gadget/function/f_fs.c > +++ b/drivers/usb/gadget/function/f_fs.c > @@ -3826,14 +3826,7 @@ 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); You forgot the error checking :(
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 801a8b6..2f904f0 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -3826,14 +3826,7 @@ 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); pr_vdebug("Buffer from user space:\n"); ffs_dump_mem("", data, len);