Use memdup_user() helper instead of open-coding to simplify the code. Signed-off-by: Geliang Tang <geliangtang@xxxxxxxxx> --- 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))) + return data; pr_vdebug("Buffer from user space:\n"); ffs_dump_mem("", data, len); -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html