Commit 35d13c7a authored by Andy Shevchenko's avatar Andy Shevchenko

platform/x86: thinkpad_acpi: Use strndup_user() in dispatch_proc_write()

Simplify the user copy code by using strndup_user().
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
parent be51bd45
...@@ -885,19 +885,11 @@ static ssize_t dispatch_proc_write(struct file *file, ...@@ -885,19 +885,11 @@ static ssize_t dispatch_proc_write(struct file *file,
if (!ibm || !ibm->write) if (!ibm || !ibm->write)
return -EINVAL; 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)) { kernbuf = strndup_user(userbuf, PAGE_SIZE);
kfree(kernbuf); if (IS_ERR(kernbuf))
return -EFAULT; return PTR_ERR(kernbuf);
}
kernbuf[count] = 0;
ret = ibm->write(kernbuf); ret = ibm->write(kernbuf);
if (ret == 0) if (ret == 0)
ret = count; ret = count;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment