f2fs: fix to check return value __allocate_new_segment
authorZhiguo Niu <zhiguo.niu@unisoc.com>
Fri, 1 Mar 2024 08:25:54 +0000 (16:25 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Mon, 4 Mar 2024 17:52:51 +0000 (09:52 -0800)
__allocate_new_segment may return error when get_new_segment
fails, so its caller should check its return value.

Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/f2fs.h
fs/f2fs/recovery.c
fs/f2fs/segment.c

index db05fd02350a5275dcefe9d6fc8225f9cf844329..433101223e7a989d68eadff3661ad298bcf0147e 100644 (file)
@@ -3705,7 +3705,7 @@ void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
                                        unsigned int start, unsigned int end);
 int f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, bool force);
 int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi);
-void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
+int f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
 int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
 bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
                                        struct cp_control *cpc);
index 3078d5613748036a75281eea1075775e0527f8cb..c381f0af33f3f5df883910d14607b1a1dc30db58 100644 (file)
@@ -851,7 +851,7 @@ next:
                f2fs_ra_meta_pages_cond(sbi, blkaddr, ra_blocks);
        }
        if (!err)
-               f2fs_allocate_new_segments(sbi);
+               err = f2fs_allocate_new_segments(sbi);
        return err;
 }
 
index 0d21ce615cecd9f5b99b03effed7e682265f2865..e284a3dc97c4ac7ced5a65f8f21f015c6fcc505f 100644 (file)
@@ -3163,16 +3163,19 @@ retry:
        return err;
 }
 
-void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi)
+int f2fs_allocate_new_segments(struct f2fs_sb_info *sbi)
 {
        int i;
+       int err = 0;
 
        f2fs_down_read(&SM_I(sbi)->curseg_lock);
        down_write(&SIT_I(sbi)->sentry_lock);
        for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++)
-               __allocate_new_segment(sbi, i, false, false);
+               err += __allocate_new_segment(sbi, i, false, false);
        up_write(&SIT_I(sbi)->sentry_lock);
        f2fs_up_read(&SM_I(sbi)->curseg_lock);
+
+       return err;
 }
 
 bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,