summaryrefslogtreecommitdiffstats
path: root/fs/f2fs
diff options
context:
space:
mode:
authorChao Yu <chao@kernel.org>2023-04-05 22:45:36 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-05-11 23:17:18 +0900
commit9c4af9874c2136399c76e7d1489ed2cb3d03c810 (patch)
tree95befdeeaffd1de04249f2a586ea846d1d9ac7a9 /fs/f2fs
parent988799a264ece63ad10e1319094c2c11c942a061 (diff)
downloadlinux-stable-9c4af9874c2136399c76e7d1489ed2cb3d03c810.tar.gz
linux-stable-9c4af9874c2136399c76e7d1489ed2cb3d03c810.tar.bz2
linux-stable-9c4af9874c2136399c76e7d1489ed2cb3d03c810.zip
f2fs: fix to check return value of inc_valid_block_count()
[ Upstream commit 935fc6fa6466cf18dd72dd1518ebc7bfc4cd58a4 ] In __replace_atomic_write_block(), we missed to check return value of inc_valid_block_count(), for extreme testcase that f2fs image is run out of space, it may cause inconsistent status in between SIT table and total valid block count. Cc: Daeho Jeong <daehojeong@google.com> Fixes: 3db1de0e582c ("f2fs: change the current atomic write way") Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'fs/f2fs')
-rw-r--r--fs/f2fs/segment.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 1ca12ea8723b..b2a080c660c8 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -246,10 +246,16 @@ retry:
} else {
blkcnt_t count = 1;
+ err = inc_valid_block_count(sbi, inode, &count);
+ if (err) {
+ f2fs_put_dnode(&dn);
+ return err;
+ }
+
*old_addr = dn.data_blkaddr;
f2fs_truncate_data_blocks_range(&dn, 1);
dec_valid_block_count(sbi, F2FS_I(inode)->cow_inode, count);
- inc_valid_block_count(sbi, inode, &count);
+
f2fs_replace_block(sbi, &dn, dn.data_blkaddr, new_addr,
ni.version, true, false);
}