]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
cachefiles: Fix the incorrect return value in __cachefiles_write()
authorZizhi Wo <wozizhi@huawei.com>
Thu, 3 Jul 2025 02:44:18 +0000 (10:44 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 24 Jul 2025 06:51:51 +0000 (08:51 +0200)
commita735ae46a9b8b65e720cc6e79e24e087f751c3f6
tree5cc413b28db1d8967a68d0b4fe71dfd97f64c93e
parent61d5fa45ed13e42af14c7e959baba9908b8ee6d4
cachefiles: Fix the incorrect return value in __cachefiles_write()

[ Upstream commit 6b89819b06d8d339da414f06ef3242f79508be5e ]

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: 047487c947e8 ("cachefiles: Implement the I/O routines")
Signed-off-by: Zizhi Wo <wozizhi@huawei.com>
Link: https://lore.kernel.org/20250703024418.2809353-1-wozizhi@huaweicloud.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/cachefiles/io.c
fs/cachefiles/ondemand.c