Re: [f2fs-dev] [PATCH] f2fs: fix to avoid potential reference count leak in do_garbage_collect()
From: Daeho Jeong
Date: Fri Oct 16 2026 - 12:05:52 EST
On Thu, Oct 15, 2026 at 7:22 PM Chao Yu via Linux-f2fs-devel
<linux-f2fs-devel@xxxxxxxxxxxxxxxxxxxxx> wrote:
>
> From: Chao Yu <chao@xxxxxxxxxx>
>
> In do_garbage_collect(), we have reserved reference counts on summary cache
> of all segments, once gc_thread encounter freezing, we need to release all
> reference counts.
>
> Cc: stable@xxxxxxxxxx
> Cc: Daeho Jeong <daehojeong@xxxxxxxxxx>
> Fixes: 02d91398a602 ("f2fs: fix to freeze GC and discard threads quickly")
> Signed-off-by: Chao Yu <chao@xxxxxxxxxx>
> ---
> fs/f2fs/gc.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> index 5bb117e5e811..ad6f604cc27f 100644
> --- a/fs/f2fs/gc.c
> +++ b/fs/f2fs/gc.c
> @@ -1901,6 +1901,9 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
> if (block_end_segno > end_segno)
> block_end_segno = end_segno;
>
> + if (unlikely(freezing(current)))
> + goto next_block;
> +
> if (is_cursec(sbi, GET_SEC_FROM_SEG(sbi, segno))) {
> f2fs_err(sbi, "%s: segment %u is used by log",
> __func__, segno);
> @@ -1968,12 +1971,6 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
> sbi->next_victim_seg[gc_type] =
> (cur_segno + 1 < sec_end_segno) ?
> cur_segno + 1 : NULL_SEGNO;
> -
> - if (unlikely(freezing(current))) {
> - f2fs_put_cache(sum_entry, false);
> - f2fs_put_cache(sum_entry, false);
> - goto stop;
> - }
> }
> next_block:
> f2fs_put_cache(sum_entry, false);
> @@ -1981,7 +1978,6 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
> segno = block_end_segno;
> }
>
> -stop:
> if (submitted)
> f2fs_submit_merged_write(sbi, data_type);
>
> --
> 2.49.0
>
>
Reviewed-by: Daeho Jeong <daehojeong@xxxxxxxxxx>
Thanks,
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel