From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 739902A1D7; Wed, 21 Feb 2024 13:38:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708522705; cv=none; b=MIGFSK1Qe8C7bW7bXXrGW7skMu+VZN4fiGUmNXa1IZOHjEoBqSQwZPVE8ImGT7kcBNVlWvCX/MqJ+J6vCVo0IjXCUL/pIEeP8tu3uOSFfRQ9t1Fe+QGcDR841+es4d3Qjb1Y11e6JQe5aG8gpy0Ohs9ixT+JCm+Rra1M9XgdlJ8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708522705; c=relaxed/simple; bh=qEyh5l8YTpu8GubhBOvskUayNDV2sv4HjgUtVufaKKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ns58Nzo8dox+2NJrShfiXiJ6m1iJBIrsw0fC23/cHfCbaRhaS0Hj+m8NnxLil9na5VgL5vuEsnx0oUB2++/URABqMlsIbdcZCloxMcaK4kjlJY1dhplAzbkp+dc84Y3QYVZVQhtFRSWLwn8wDfjRf7NuYkoyvauAhG2VZVXKw/o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hS6RqQ0m; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="hS6RqQ0m" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D48DC433C7; Wed, 21 Feb 2024 13:38:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708522704; bh=qEyh5l8YTpu8GubhBOvskUayNDV2sv4HjgUtVufaKKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hS6RqQ0m/Aa3q0KUmnCgih5PYPrL4GsdO3H0j3pW7Opy45vBVp46QLlXpRuVauZPy 67xYNbh9uQFZj7g3dpz+EYF1f8+4Vdne4Xf2ewjJ8DTolxs+RntUSXzzkh3+12lN7z VrI8MYPmMPk6b9fcrMqCG8+2lG6VIsmTfmrX5aoY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.15 208/476] f2fs: fix to check return value of f2fs_reserve_new_block() Date: Wed, 21 Feb 2024 14:04:19 +0100 Message-ID: <20240221130015.602303937@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221130007.738356493@linuxfoundation.org> References: <20240221130007.738356493@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chao Yu [ Upstream commit 956fa1ddc132e028f3b7d4cf17e6bfc8cb36c7fd ] Let's check return value of f2fs_reserve_new_block() in do_recover_data() rather than letting it fails silently. Also refactoring check condition on return value of f2fs_reserve_new_block() as below: - trigger f2fs_bug_on() only for ENOSPC case; - use do-while statement to avoid redundant codes; Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/recovery.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index ba7eeb3c2738..da0801aa4118 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -657,7 +657,16 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, */ if (dest == NEW_ADDR) { f2fs_truncate_data_blocks_range(&dn, 1); - f2fs_reserve_new_block(&dn); + do { + err = f2fs_reserve_new_block(&dn); + if (err == -ENOSPC) { + f2fs_bug_on(sbi, 1); + break; + } + } while (err && + IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)); + if (err) + goto err; continue; } @@ -665,12 +674,14 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, if (f2fs_is_valid_blkaddr(sbi, dest, META_POR)) { if (src == NULL_ADDR) { - err = f2fs_reserve_new_block(&dn); - while (err && - IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) + do { err = f2fs_reserve_new_block(&dn); - /* We should not get -ENOSPC */ - f2fs_bug_on(sbi, err); + if (err == -ENOSPC) { + f2fs_bug_on(sbi, 1); + break; + } + } while (err && + IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)); if (err) goto err; } -- 2.43.0