xtensa/simdisk: fix proc_read_simdisk()
commit b011946d039d66bbc7102137e98cc67e1356aa87 upstream. The commita69755b187
("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:a69755b187
("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>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
63758dd959
commit
d787a57a17
@@ -213,12 +213,18 @@ static ssize_t proc_read_simdisk(struct file *file, char __user *buf,
|
|||||||
struct simdisk *dev = PDE_DATA(file_inode(file));
|
struct simdisk *dev = PDE_DATA(file_inode(file));
|
||||||
const char *s = dev->filename;
|
const char *s = dev->filename;
|
||||||
if (s) {
|
if (s) {
|
||||||
ssize_t n = simple_read_from_buffer(buf, size, ppos,
|
ssize_t len = strlen(s);
|
||||||
s, strlen(s));
|
char *temp = kmalloc(len + 2, GFP_KERNEL);
|
||||||
if (n < 0)
|
|
||||||
return n;
|
if (!temp)
|
||||||
buf += n;
|
return -ENOMEM;
|
||||||
size -= n;
|
|
||||||
|
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);
|
return simple_read_from_buffer(buf, size, ppos, "\n", 1);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user