Skip to content

Commit

Permalink
platform/x86: thinkpad_acpi: Use strndup_user() in dispatch_proc_write()
Browse files Browse the repository at this point in the history
Simplify the user copy code by using strndup_user().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  • Loading branch information
Andy Shevchenko committed May 15, 2020
1 parent be51bd4 commit 35d13c7
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions drivers/platform/x86/thinkpad_acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 35d13c7

Please sign in to comment.