platform/x86: toshiba_acpi: use memdup_user_nul
authorGeliang Tang <geliangtang@gmail.com>
Sat, 6 May 2017 15:40:19 +0000 (23:40 +0800)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 15 May 2017 09:06:10 +0000 (12:06 +0300)
Use memdup_user_nul() helper instead of open-coding to simplify the
code.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
drivers/platform/x86/toshiba_acpi.c

index d0daf75cbed1392711518d0b8e6a46ba1e192a7e..88f9f79a7cf605ce6d8624d4f3f6826854cf0796 100644 (file)
@@ -1502,14 +1502,9 @@ static ssize_t video_proc_write(struct file *file, const char __user *buf,
        int ret;
        u32 video_out;
 
-       cmd = kmalloc(count + 1, GFP_KERNEL);
-       if (!cmd)
-               return -ENOMEM;
-       if (copy_from_user(cmd, buf, count)) {
-               kfree(cmd);
-               return -EFAULT;
-       }
-       cmd[count] = '\0';
+       cmd = memdup_user_nul(buf, count);
+       if (IS_ERR(cmd))
+               return PTR_ERR(cmd);
 
        buffer = cmd;