Skip to contentSkip to conversation

kernfs: fix regression in kernfs_fop_write caused by wrong type

PATCH Applied Ivan Vecera 3 participants 3 messages Jan 19, 2018 kernfs

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernfs: fix regression in kernfs_fop_write caused by wrong type

Commit b7ce40cff0b9 ("kernfs: cache atomic_write_len in kernfs_open_file") changes type of local variable 'len' from ssize_t to size_t. This change caused that the *ppos value is updated also when the previous write callback failed.

Mentioned snippet:
...
len = ops->write(...); <- return value can be negative
...
if (len > 0) <- true here in this case

        *ppos += len;

...

Fixes b7ce40cff0b9 ("kernfs: cache atomic_write_len in kernfs_open_file")
---
 fs/kernfs/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/kernfs/file.c +1 -1
index 9698e51656b1..d8f49c412f50 100644
@@ -275,7 +275,7 @@ static ssize_t kernfs_fop_write(struct file *file, const char __user *user_buf,
 {
 	struct kernfs_open_file *of = kernfs_of(file);
 	const struct kernfs_ops *ops;
-	size_t len;
+	ssize_t len;
 	char *buf;
 
 	if (of->atomic_write_len) {
Signature · 1 line
2.13.6
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Ivan Vecera

Commit b7ce40cff0b9 ("kernfs: cache atomic_write_len in kernfs_open_file") changes type of local variable 'len' from ssize_t to size_t. This change caused that the *ppos value is updated also when the previous write callback failed.

Mentioned snippet:
...
len = ops->write(...); <- return value can be negative
...
if (len > 0) <- true here in this case

Quoted 5 lines
        *ppos += len;

...

Fixes b7ce40cff0b9 ("kernfs: cache atomic_write_len in kernfs_open_file")

Oops.

Thanks.

Signature · 1 line
tejun
Applied
#2 lore raw
Quoted 14 lines · Tejun Heo
Quoted 13 lines · Ivan Vecera

Commit b7ce40cff0b9 ("kernfs: cache atomic_write_len in kernfs_open_file") changes type of local variable 'len' from ssize_t to size_t. This change caused that the *ppos value is updated also when the previous write callback failed.

Mentioned snippet:
...
len = ops->write(...); <- return value can be negative
...
if (len > 0) <- true here in this case

        *ppos += len;

...

Quoted 6 lines
Quoted 2 lines
Fixes b7ce40cff0b9 ("kernfs: cache atomic_write_len in kernfs_open_file")

Oops.

Applied.