Implement ->proc_write_buf() so procfs copies in what is written to
/proc/acpi/ibm/* before it pins the entry, and hand that copy to
->write(). procfs already rejects writes larger than PAGE_SIZE - 1
bytes.

Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
 drivers/platform/x86/lenovo/thinkpad_acpi.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c 
b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 01e4c980fad6..b4f253da9536 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -881,33 +881,25 @@ static int dispatch_proc_show(struct seq_file *m, void *v)
 }
 
 static ssize_t dispatch_proc_write(struct file *file,
-                       const char __user *userbuf,
+                       char *buf,
                        size_t count, loff_t *pos)
 {
        struct ibm_struct *ibm = pde_data(file_inode(file));
-       char *kernbuf;
        int ret;
 
        if (!ibm || !ibm->write)
                return -EINVAL;
-       if (count > PAGE_SIZE - 1)
-               return -EINVAL;
 
-       kernbuf = memdup_user_nul(userbuf, count);
-       if (IS_ERR(kernbuf))
-               return PTR_ERR(kernbuf);
-       ret = ibm->write(kernbuf);
+       ret = ibm->write(buf);
        if (ret == 0)
                ret = count;
 
-       kfree(kernbuf);
-
        return ret;
 }
 
 static const struct proc_ops dispatch_proc_ops = {
        .proc_show      = dispatch_proc_show,
-       .proc_write     = dispatch_proc_write,
+       .proc_write_buf = dispatch_proc_write,
 };
 
 /****************************************************************************

-- 
2.53.0

Reply via email to