summaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorYi Yang <yiyang13@huawei.com>2022-05-10 16:05:33 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-06-09 10:23:28 +0200
commit4b02493838d9057b1062c55c678b18ffe291b9d7 (patch)
tree2365d0eb08ece7bcd4ecf5998c2964ccde90be98 /arch
parentfd9a5081ee3311a3ceee9f0f3ddbf508e119b580 (diff)
downloadlinux-stable-4b02493838d9057b1062c55c678b18ffe291b9d7.tar.gz
linux-stable-4b02493838d9057b1062c55c678b18ffe291b9d7.tar.bz2
linux-stable-4b02493838d9057b1062c55c678b18ffe291b9d7.zip
xtensa/simdisk: fix proc_read_simdisk()
commit b011946d039d66bbc7102137e98cc67e1356aa87 upstream. The commit a69755b18774 ("xtensa simdisk: switch to proc_create_data()") split read operation into two parts, first retrieving the path when it's non-null and second retrieving the trailing '\n'. However when the path is non-null the first simple_read_from_buffer updates ppos, and the second simple_read_from_buffer returns 0 if ppos is greater than 1 (i.e. almost always). As a result reading from that proc file is almost always empty. Fix it by making a temporary copy of the path with the trailing '\n' and using simple_read_from_buffer on that copy. Cc: stable@vger.kernel.org Fixes: a69755b18774 ("xtensa simdisk: switch to proc_create_data()") Signed-off-by: Yi Yang <yiyang13@huawei.com> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/xtensa/platforms/iss/simdisk.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/arch/xtensa/platforms/iss/simdisk.c b/arch/xtensa/platforms/iss/simdisk.c
index 3cdfa00738e0..edb27649851f 100644
--- a/arch/xtensa/platforms/iss/simdisk.c
+++ b/arch/xtensa/platforms/iss/simdisk.c
@@ -212,12 +212,18 @@ static ssize_t proc_read_simdisk(struct file *file, char __user *buf,
struct simdisk *dev = PDE_DATA(file_inode(file));
const char *s = dev->filename;
if (s) {
- ssize_t n = simple_read_from_buffer(buf, size, ppos,
- s, strlen(s));
- if (n < 0)
- return n;
- buf += n;
- size -= n;
+ ssize_t len = strlen(s);
+ char *temp = kmalloc(len + 2, GFP_KERNEL);
+
+ if (!temp)
+ return -ENOMEM;
+
+ len = scnprintf(temp, len + 2, "%s\n", s);
+ len = simple_read_from_buffer(buf, size, ppos,
+ temp, len);
+
+ kfree(temp);
+ return len;
}
return simple_read_from_buffer(buf, size, ppos, "\n", 1);
}