Browse Source

platform/x86: toshiba_acpi: use memdup_user_nul

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>
Geliang Tang 8 years ago
parent
commit
f0ee1a6d31
1 changed files with 3 additions and 8 deletions
  1. 3 8
      drivers/platform/x86/toshiba_acpi.c

+ 3 - 8
drivers/platform/x86/toshiba_acpi.c

@@ -1502,14 +1502,9 @@ static ssize_t video_proc_write(struct file *file, const char __user *buf,
 	int ret;
 	int ret;
 	u32 video_out;
 	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;
 	buffer = cmd;