f2fs: fix uninitialized skipped_gc_rwsem
[platform/kernel/linux-starfive.git] / fs / f2fs / gc.c
index f46e4dc..aa928d1 100644 (file)
@@ -1078,7 +1078,7 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
 {
        struct page *node_page;
        nid_t nid;
-       unsigned int ofs_in_node, max_addrs;
+       unsigned int ofs_in_node, max_addrs, base;
        block_t source_blkaddr;
 
        nid = le32_to_cpu(sum->nid);
@@ -1104,11 +1104,18 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
                return false;
        }
 
-       max_addrs = IS_INODE(node_page) ? DEF_ADDRS_PER_INODE :
-                                               DEF_ADDRS_PER_BLOCK;
-       if (ofs_in_node >= max_addrs) {
-               f2fs_err(sbi, "Inconsistent ofs_in_node:%u in summary, ino:%u, nid:%u, max:%u",
-                       ofs_in_node, dni->ino, dni->nid, max_addrs);
+       if (IS_INODE(node_page)) {
+               base = offset_in_addr(F2FS_INODE(node_page));
+               max_addrs = DEF_ADDRS_PER_INODE;
+       } else {
+               base = 0;
+               max_addrs = DEF_ADDRS_PER_BLOCK;
+       }
+
+       if (base + ofs_in_node >= max_addrs) {
+               f2fs_err(sbi, "Inconsistent blkaddr offset: base:%u, ofs_in_node:%u, max:%u, ino:%u, nid:%u",
+                       base, ofs_in_node, max_addrs, dni->ino, dni->nid);
+               f2fs_put_page(node_page, 1);
                return false;
        }
 
@@ -1743,8 +1750,9 @@ freed:
                                get_valid_blocks(sbi, segno, false) == 0)
                        seg_freed++;
 
-               if (__is_large_section(sbi) && segno + 1 < end_segno)
-                       sbi->next_victim_seg[gc_type] = segno + 1;
+               if (__is_large_section(sbi))
+                       sbi->next_victim_seg[gc_type] =
+                               (segno + 1 < end_segno) ? segno + 1 : NULL_SEGNO;
 skip:
                f2fs_put_page(sum_page, 0);
        }
@@ -1784,8 +1792,8 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
                                prefree_segments(sbi));
 
        cpc.reason = __get_cp_reason(sbi);
-       sbi->skipped_gc_rwsem = 0;
 gc_more:
+       sbi->skipped_gc_rwsem = 0;
        if (unlikely(!(sbi->sb->s_flags & SB_ACTIVE))) {
                ret = -EINVAL;
                goto stop;