aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/drivers/platform
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2020-05-11 15:54:14 +0300
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>2020-05-15 15:45:14 +0300
commit35d13c7a05126a5a54a1ef40aff4c6984474e604 (patch)
tree07fbecfba23dd360d99e396c290e5a6a4c51930c /drivers/platform
parentplatform/x86: thinkpad_acpi: Replace next_cmd(&buf) with strsep(&buf, ",") (diff)
downloadwireguard-linux-35d13c7a05126a5a54a1ef40aff4c6984474e604.tar.xz
wireguard-linux-35d13c7a05126a5a54a1ef40aff4c6984474e604.zip
platform/x86: thinkpad_acpi: Use strndup_user() in dispatch_proc_write()
Simplify the user copy code by using strndup_user(). Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Diffstat (limited to 'drivers/platform')
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 6fb540d02dac..bf651b850faa 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -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;