Skip to content

Commit 6b89819

Browse files
Zizhi Wobrauner
authored andcommitted
cachefiles: Fix the incorrect return value in __cachefiles_write()
In __cachefiles_write(), if the return value of the write operation > 0, it is set to 0. This makes it impossible to distinguish scenarios where a partial write has occurred, and will affect the outer calling functions: 1) cachefiles_write_complete() will call "term_func" such as netfs_write_subrequest_terminated(). When "ret" in __cachefiles_write() is used as the "transferred_or_error" of this function, it can not distinguish the amount of data written, makes the WARN meaningless. 2) cachefiles_ondemand_fd_write_iter() can only assume all writes were successful by default when "ret" is 0, and unconditionally return the full length specified by user space. Fix it by modifying "ret" to reflect the actual number of bytes written. Furthermore, returning a value greater than 0 from __cachefiles_write() does not affect other call paths, such as cachefiles_issue_write() and fscache_write(). Fixes: 047487c ("cachefiles: Implement the I/O routines") Signed-off-by: Zizhi Wo <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 98f9939 commit 6b89819

File tree

2 files changed

+1
-5
lines changed

2 files changed

+1
-5
lines changed

fs/cachefiles/io.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,6 @@ int __cachefiles_write(struct cachefiles_object *object,
347347
default:
348348
ki->was_async = false;
349349
cachefiles_write_complete(&ki->iocb, ret);
350-
if (ret > 0)
351-
ret = 0;
352350
break;
353351
}
354352

fs/cachefiles/ondemand.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ static ssize_t cachefiles_ondemand_fd_write_iter(struct kiocb *kiocb,
8383

8484
trace_cachefiles_ondemand_fd_write(object, file_inode(file), pos, len);
8585
ret = __cachefiles_write(object, file, pos, iter, NULL, NULL);
86-
if (!ret) {
87-
ret = len;
86+
if (ret > 0)
8887
kiocb->ki_pos += ret;
89-
}
9088

9189
out:
9290
fput(file);

0 commit comments

Comments
 (0)