wlcore: use memdup_user
authorGeliang Tang <geliangtang@gmail.com>
Sat, 6 May 2017 15:42:20 +0000 (23:42 +0800)
committerKalle Valo <kvalo@codeaurora.org>
Thu, 18 May 2017 13:41:23 +0000 (16:41 +0300)
Use memdup_user() helper instead of open-coding to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/ti/wlcore/debugfs.c

index de7e2a5fdffa048e2f00f2edab72f9363b56e01a..a2cb408be8aaaae14afccd23d7f29db0d903c837 100644 (file)
@@ -1149,15 +1149,9 @@ static ssize_t dev_mem_write(struct file *file, const char __user *user_buf,
        part.mem.start = *ppos;
        part.mem.size = bytes;
 
-       buf = kmalloc(bytes, GFP_KERNEL);
-       if (!buf)
-               return -ENOMEM;
-
-       ret = copy_from_user(buf, user_buf, bytes);
-       if (ret) {
-               ret = -EFAULT;
-               goto err_out;
-       }
+       buf = memdup_user(user_buf, bytes);
+       if (IS_ERR(buf))
+               return PTR_ERR(buf);
 
        mutex_lock(&wl->mutex);
 
@@ -1197,7 +1191,6 @@ skip_write:
        if (ret == 0)
                *ppos += bytes;
 
-err_out:
        kfree(buf);
 
        return ((ret == 0) ? bytes : ret);