drm: solve debug node write string issue [1/1]
authorAo Xu <ao.xu@amlogic.com>
Wed, 23 Oct 2019 11:24:27 +0000 (19:24 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Wed, 6 Nov 2019 10:26:29 +0000 (03:26 -0700)
PD#SWPL-15143

Problem:
userspace program use the write() syscall to write the node.
when write the strlen() length content, it will fail.

Solution:
use the buf[size] to instead of buf[size-1]

Verify:
U200

Change-Id: I886d9a1cbf3da459476bca76c9a5708ecbc20afe
Signed-off-by: Ao Xu <ao.xu@amlogic.com>
drivers/amlogic/drm/meson_debugfs.c

index dbab11f..ff9eea8 100644 (file)
@@ -59,7 +59,9 @@ static ssize_t meson_dump_write(struct file *file, const char __user *ubuf,
 
        if (copy_from_user(buf, ubuf, len))
                return -EFAULT;
-       buf[len - 1] = '\0';
+       if (buf[len - 1] == '\n')
+               buf[len - 1] = '\0';
+       buf[len] = '\0';
 
        if (strncmp(buf, "0", 1) == 0) {
                amc->dump_enable = 0;
@@ -193,7 +195,9 @@ static ssize_t meson_blank_write(struct file *file, const char __user *ubuf,
 
        if (copy_from_user(buf, ubuf, len))
                return -EFAULT;
-       buf[len - 1] = '\0';
+       if (buf[len - 1] == '\n')
+               buf[len - 1] = '\0';
+       buf[len] = '\0';
 
        if (strncmp(buf, "1", 1) == 0) {
                amc->blank_enable = 1;