kernfs: fix regression in kernfs_fop_write caused by wrong type
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;
...
--- fs/kernfs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/kernfs/file.c +1 -1
@@ -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
Quoted 10 lines · Ivan Vecera
Commit
b7ce40cff0b9("kernfs: cacheatomic_write_leninkernfs_open_file") changes type of local variable 'len' fromssize_ttosize_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")Signed-off-by Ivan Vecera <[email protected]>
Oops.
Thanks.
Signature · 1 line
tejun
Al Viro
AppliedQuoted 14 lines · Tejun Heo
Quoted 13 lines · Ivan Vecera
Commit
b7ce40cff0b9("kernfs: cacheatomic_write_leninkernfs_open_file") changes type of local variable 'len' fromssize_ttosize_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")Signed-off-by Ivan Vecera <[email protected]>Oops.
Acked-by Tejun Heo <[email protected]>
Applied.