platform/x86: thinkpad_acpi: Use strndup_user() in dispatch_proc_write()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 11 May 2020 12:54:14 +0000 (15:54 +0300)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 15 May 2020 12:45:14 +0000 (15:45 +0300)
Simplify the user copy code by using strndup_user().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
drivers/platform/x86/thinkpad_acpi.c

index 6fb540d02dac87d02b489836359b4ec1e3676fba..bf651b850faa251a8a979163a2c22346aaa2f37b 100644 (file)
@@ -885,19 +885,11 @@ static ssize_t dispatch_proc_write(struct file *file,
 
        if (!ibm || !ibm->write)
                return -EINVAL;
-       if (count > PAGE_SIZE - 1)
-               return -EINVAL;
-
-       kernbuf = kmalloc(count + 1, GFP_KERNEL);
-       if (!kernbuf)
-               return -ENOMEM;
 
-       if (copy_from_user(kernbuf, userbuf, count)) {
-               kfree(kernbuf);
-               return -EFAULT;
-       }
+       kernbuf = strndup_user(userbuf, PAGE_SIZE);
+       if (IS_ERR(kernbuf))
+               return PTR_ERR(kernbuf);
 
-       kernbuf[count] = 0;
        ret = ibm->write(kernbuf);
        if (ret == 0)
                ret = count;