]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
USB: gadget: f_fs: fix memdup_user.cocci warnings
authorkernel test robot <lkp@intel.com>
Mon, 8 Mar 2021 07:09:51 +0000 (15:09 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 23 Mar 2021 14:24:26 +0000 (15:24 +0100)
drivers/usb/gadget/function/f_fs.c:3829:8-15: WARNING opportunity for memdup_user

 Use memdup_user rather than duplicating its implementation
 This is a little bit restricted to reduce false positives

Generated by: scripts/coccinelle/api/memdup_user.cocci

Fixes: 8704fd73bf56 ("USB: gadget: f_fs: remove likely/unlikely")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/r/20210308070951.GA83949@8a16bdd473dc
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/f_fs.c

index 10a5d9f0f2b902e7250ff142d08d1009f176b257..bf109191659a5362c5edae0480d75736b10f28fe 100644 (file)
@@ -3827,14 +3827,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 ERR_PTR(PTR_ERR(data));
 
        pr_vdebug("Buffer from user space:\n");
        ffs_dump_mem("", data, len);