f2fs: fix to avoid potential panic during recovery
authorChao Yu <chao@kernel.org>
Wed, 24 Jan 2024 14:49:15 +0000 (22:49 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 6 Feb 2024 02:58:41 +0000 (18:58 -0800)
commit21ec68234826b1b54ab980a8df6e33c74cfbee58
treec31c6a934a70fe3865268db396b803a0f5db9c47
parent8e9c1a349b5e227f687fa6f047e1a785b07371ea
f2fs: fix to avoid potential panic during recovery

During recovery, if FAULT_BLOCK is on, it is possible that
f2fs_reserve_new_block() will return -ENOSPC during recovery,
then it may trigger panic.

Also, if fault injection rate is 1 and only FAULT_BLOCK fault
type is on, it may encounter deadloop in loop of block reservation.

Let's change as below to fix these issues:
- remove bug_on() to avoid panic.
- limit the loop count of block reservation to avoid potential
deadloop.

Fixes: 956fa1ddc132 ("f2fs: fix to check return value of f2fs_reserve_new_block()")
Reported-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/f2fs.h
fs/f2fs/recovery.c