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 573637C6C0; Wed, 21 Feb 2024 14:22:02 +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=1708525323; cv=none; b=fhH6Lyvg8HHXQqNfIXrqwuB5u628VrINyQHpWictO9aZWWAbrz2XpCHEEO9mi9uRmqN9QDHoOo2J9Qn59v2oB1iiSs2CZjgUnX9C7XJhxhmWAOYBbLPFxO8pCBwTTG2hLpHlGt9mDNeXwUR4e8eLq1zdFLwMtfjJlwkG/QidKQc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708525323; c=relaxed/simple; bh=d37JeiK6eN/UhtIPAS/esmB+ijDieC3j8OJUF04fjA4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YMeJ0xOd01oMHTOaGBFQ0I2UwYKajAAh2/cvlhjtR7uFLwRWzYeI1zN95Fbx0cb0osY7tjKQHOTEMaW5iM6KGh6m/QmDWgNSGG/YgmpelWHHLt2ZzloA6xYXMPmWq0y58pywWX/GQu9iQSWNt2zoqgE4RWEWPmiQPUIj0yDaLpI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=nTzu+P1B; 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="nTzu+P1B" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6475C433F1; Wed, 21 Feb 2024 14:22:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708525322; bh=d37JeiK6eN/UhtIPAS/esmB+ijDieC3j8OJUF04fjA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nTzu+P1BMfAgAQACvfmjc6eUyScHq3evW0m5Uah7f/M6IhwcdfywouJrP7eCGO8Tw 12NsFQB9kAHfUkeg0N9mA2ExhYDYZZbxNKhyggmHuYzvbqScGXqPkLcPI57SOn5ZpK KtS82GootHUzwLfi/u0aINoyl3TGmhzxHv5BPosE= 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.4 120/267] f2fs: fix to check return value of f2fs_reserve_new_block() Date: Wed, 21 Feb 2024 14:07:41 +0100 Message-ID: <20240221125943.751969994@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221125940.058369148@linuxfoundation.org> References: <20240221125940.058369148@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.4-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 da123c6d3ce0..7e30326b296c 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -611,7 +611,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; } @@ -619,12 +628,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