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 71397F9EB; Sat, 3 Feb 2024 04:13:30 +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=1706933610; cv=none; b=AuXJroQVgG54yaK7FeMValtLjVIxqcsWX5PXUttKHawjaCylIfOsOzGqGMC8tCrBoimUiMbzZg6/JQFUG2zxaRoMXWuYhrSjRk9YrR+BGnPZuwEUo9wajUi0+8HExh8VGJZUIy78+rDPeUA1xyVwcTTYPUOyKfRsoRxWEVn4Res= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706933610; c=relaxed/simple; bh=dAExpXJexkih4ig8Nl+oFU89zu3iocy186e8RoglAqM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cE3BQZ+5PkguTyvh7IfAiCfSCAQ+X/tMi1K4tTn3aOfuzSkoLnX2kp/3G0LVf8hjPQS0eaGS0FFYGBhxLqNh1PWtPzbiPigR5FII/POsgcqzHFCtVZY/m/OWEMOKT1nDTTZX35Mkr6ujkeHVJnG2lxSJfY1kyyvqm6o0qNVi+mw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=QexpjGIW; 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="QexpjGIW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CDCBC43399; Sat, 3 Feb 2024 04:13:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1706933610; bh=dAExpXJexkih4ig8Nl+oFU89zu3iocy186e8RoglAqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QexpjGIWSY5kYxxVo6EcMhzKBg5WS/gsD2yCq32Sa5tdW89iZLebJZ+pl6ptF9HoY D0jukL9wmJWNjyQurj1WE/CecPVo6paD1pItxWQFnUbc6kTB9jmPZpwiXidGqRe1DK h3U4Gyav0gN7/t6iQHVJa4HufPPPg9MEdvZe0Xmg= 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 6.6 157/322] f2fs: fix to check return value of f2fs_reserve_new_block() Date: Fri, 2 Feb 2024 20:04:14 -0800 Message-ID: <20240203035404.294602832@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240203035359.041730947@linuxfoundation.org> References: <20240203035359.041730947@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-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 7be60df277a5..f0de36ef73c2 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -712,7 +712,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; } @@ -720,12 +729,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