Skip to content

Commit 35d13c7

Browse files
committed
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 <[email protected]>
1 parent be51bd4 commit 35d13c7

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

drivers/platform/x86/thinkpad_acpi.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -885,19 +885,11 @@ static ssize_t dispatch_proc_write(struct file *file,
885885

886886
if (!ibm || !ibm->write)
887887
return -EINVAL;
888-
if (count > PAGE_SIZE - 1)
889-
return -EINVAL;
890-
891-
kernbuf = kmalloc(count + 1, GFP_KERNEL);
892-
if (!kernbuf)
893-
return -ENOMEM;
894888

895-
if (copy_from_user(kernbuf, userbuf, count)) {
896-
kfree(kernbuf);
897-
return -EFAULT;
898-
}
889+
kernbuf = strndup_user(userbuf, PAGE_SIZE);
890+
if (IS_ERR(kernbuf))
891+
return PTR_ERR(kernbuf);
899892

900-
kernbuf[count] = 0;
901893
ret = ibm->write(kernbuf);
902894
if (ret == 0)
903895
ret = count;

0 commit comments

Comments
 (0)