From nobody Sat Dec 27 03:15:43 2025 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E7095100A for ; Mon, 25 Dec 2023 11:14:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 3BPBDK38091375; Mon, 25 Dec 2023 19:13:20 +0800 (+08) (envelope-from Zhiguo.Niu@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4SzFTq2vzPz2QYWd5; Mon, 25 Dec 2023 19:06:55 +0800 (CST) Received: from bj08434pcu.spreadtrum.com (10.0.73.87) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 25 Dec 2023 19:13:18 +0800 From: Zhiguo Niu To: , CC: , , , , Subject: [PATCH V1] f2fs: fix potentail deadloop issue in do_recover_data Date: Mon, 25 Dec 2023 19:11:55 +0800 Message-ID: <1703502715-11936-1-git-send-email-zhiguo.niu@unisoc.com> X-Mailer: git-send-email 1.9.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 3BPBDK38091375 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There is a potentail deadloop issue in the corner case of CONFIG_F2FS_FAULT_INJECTION is enabled and the return value of f2fs_reserve_new_block is error but not -ENOSPC, such as this error case: if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC))) return -EPERM; besides, the mainly error -ENOSPC has been handled as bug on, so other error cases can be proecssed normally without looping. Fixes: 956fa1ddc132 ("f2fs: fix to check return value of f2fs_reserve_new_b= lock()") Signed-off-by: Zhiguo Niu --- fs/f2fs/recovery.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index 21381b7..5d658f6 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -710,15 +710,10 @@ static int do_recover_data(struct f2fs_sb_info *sbi, = struct inode *inode, */ if (dest =3D=3D NEW_ADDR) { f2fs_truncate_data_blocks_range(&dn, 1); - do { - err =3D f2fs_reserve_new_block(&dn); - if (err =3D=3D -ENOSPC) { - f2fs_bug_on(sbi, 1); - break; - } - } while (err && - IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)); - if (err) + err =3D f2fs_reserve_new_block(&dn); + if (err =3D=3D -ENOSPC) + f2fs_bug_on(sbi, 1); + else if (err) goto err; continue; } @@ -727,15 +722,10 @@ static int do_recover_data(struct f2fs_sb_info *sbi, = struct inode *inode, if (f2fs_is_valid_blkaddr(sbi, dest, META_POR)) { =20 if (src =3D=3D NULL_ADDR) { - do { - err =3D f2fs_reserve_new_block(&dn); - if (err =3D=3D -ENOSPC) { - f2fs_bug_on(sbi, 1); - break; - } - } while (err && - IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)); - if (err) + err =3D f2fs_reserve_new_block(&dn); + if (err =3D=3D -ENOSPC) + f2fs_bug_on(sbi, 1); + else if (err) goto err; } retry_prev: --=20 1.9.1