[PATCH] f2fs: fix use after iput() of inode in gc_data_segment()

From: Thomas Fourier

Date: Wed Nov 25 2026 - 05:36:10 EST


In phase 3 of gc_data_segment(), if f2fs_has_inline_data(inode) is true,
inode may be freed by iput() before the error message reads
inode->i_ino.

Report the error before dropping the reference.

Signed-off-by: Thomas Fourier <fourier.thomas@xxxxxxxxx>
Fixes: fc01008c92f4 ("f2fs: fix to do sanity check on F2FS_INLINE_DATA flag in inode during GC")
---
fs/f2fs/gc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 0a00180c21dc..c7dc65acd052 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -1650,12 +1650,12 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
}

if (f2fs_has_inline_data(inode)) {
- iput(inode);
set_sbi_flag(sbi, SBI_NEED_FSCK);
f2fs_err_ratelimited(sbi,
"inode %llu has both inline_data flag and "
"data block, nid=%u, ofs_in_node=%u",
inode->i_ino, dni.nid, ofs_in_node);
+ iput(inode);
continue;
}

--
2.53.0