Skip to content

Commit b011946

Browse files
Yi Yangjcmvbkbc
authored andcommitted
xtensa/simdisk: fix proc_read_simdisk()
The commit a69755b ("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: [email protected] Fixes: a69755b ("xtensa simdisk: switch to proc_create_data()") Signed-off-by: Yi Yang <[email protected]> Signed-off-by: Max Filippov <[email protected]>
1 parent c6ab42b commit b011946

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

arch/xtensa/platforms/iss/simdisk.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,18 @@ static ssize_t proc_read_simdisk(struct file *file, char __user *buf,
211211
struct simdisk *dev = pde_data(file_inode(file));
212212
const char *s = dev->filename;
213213
if (s) {
214-
ssize_t n = simple_read_from_buffer(buf, size, ppos,
215-
s, strlen(s));
216-
if (n < 0)
217-
return n;
218-
buf += n;
219-
size -= n;
214+
ssize_t len = strlen(s);
215+
char *temp = kmalloc(len + 2, GFP_KERNEL);
216+
217+
if (!temp)
218+
return -ENOMEM;
219+
220+
len = scnprintf(temp, len + 2, "%s\n", s);
221+
len = simple_read_from_buffer(buf, size, ppos,
222+
temp, len);
223+
224+
kfree(temp);
225+
return len;
220226
}
221227
return simple_read_from_buffer(buf, size, ppos, "\n", 1);
222228
}

0 commit comments

Comments
 (0)