f2fs: fix blkofs_end correctly in f2fs_migrate_blocks()
authorChao Yu <chao@kernel.org>
Mon, 26 Feb 2024 01:32:05 +0000 (09:32 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Mon, 4 Mar 2024 17:51:52 +0000 (09:51 -0800)
In f2fs_migrate_blocks(), when traversing blocks in last section,
blkofs_end should be (start_blk + blkcnt - 1) % blk_per_sec, fix it.

Signed-off-by: Chao Yu <chao@kernel.org>
Reviewed-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/data.c

index c21b92f18463e7532293eed7e63791fa78d51af3..0c728e82d9367e44890b30d43eac1a8d2263dfd9 100644 (file)
@@ -3841,13 +3841,14 @@ static int f2fs_migrate_blocks(struct inode *inode, block_t start_blk,
        struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
        unsigned int blkofs;
        unsigned int blk_per_sec = BLKS_PER_SEC(sbi);
+       unsigned int end_blk = start_blk + blkcnt - 1;
        unsigned int secidx = start_blk / blk_per_sec;
        unsigned int end_sec;
        int ret = 0;
 
        if (!blkcnt)
                return 0;
-       end_sec = secidx + (blkcnt - 1) / blk_per_sec;
+       end_sec = end_blk / blk_per_sec;
 
        f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
        filemap_invalidate_lock(inode->i_mapping);
@@ -3857,7 +3858,7 @@ static int f2fs_migrate_blocks(struct inode *inode, block_t start_blk,
 
        for (; secidx <= end_sec; secidx++) {
                unsigned int blkofs_end = secidx == end_sec ?
-                       (blkcnt - 1) % blk_per_sec : blk_per_sec - 1;
+                               end_blk % blk_per_sec : blk_per_sec - 1;
 
                f2fs_down_write(&sbi->pin_sem);