All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: reorganize error handling in btrfs_tree_mod_log_insert_key
@ 2025-09-29  6:56 Sun YangKai
  2025-09-29  7:54 ` Qu Wenruo
  2025-09-29  8:30 ` Filipe Manana
  0 siblings, 2 replies; 8+ messages in thread
From: Sun YangKai @ 2025-09-29  6:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Sun YangKai

Restructure the error handling flow in btrfs_tree_mod_log_insert_key
to address memory allocation failures more cleanly.

No functional changes are made - this is purely a code readability
improvement.

Signed-off-by: Sun YangKai <sunk67188@gmail.com>
---
 fs/btrfs/tree-mod-log.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/tree-mod-log.c b/fs/btrfs/tree-mod-log.c
index 9e8cb3b7c064..4fd7859ad7dc 100644
--- a/fs/btrfs/tree-mod-log.c
+++ b/fs/btrfs/tree-mod-log.c
@@ -267,9 +267,8 @@ int btrfs_tree_mod_log_insert_key(const struct extent_buffer *eb, int slot,
 	if (!tree_mod_need_log(eb->fs_info, eb))
 		return 0;
 
+	/* Allocation error is handled later. */
 	tm = alloc_tree_mod_elem(eb, slot, op);
-	if (!tm)
-		ret = -ENOMEM;
 
 	if (tree_mod_dont_log(eb->fs_info, eb)) {
 		kfree(tm);
@@ -278,16 +277,14 @@ int btrfs_tree_mod_log_insert_key(const struct extent_buffer *eb, int slot,
 		 * need to log.
 		 */
 		return 0;
-	} else if (ret != 0) {
-		/*
-		 * We previously failed to allocate memory and we need to log,
-		 * so we have to fail.
-		 */
-		goto out_unlock;
 	}
 
-	ret = tree_mod_log_insert(eb->fs_info, tm);
-out_unlock:
+	/* Deal with allocation error. */
+	if (tm)
+		ret = tree_mod_log_insert(eb->fs_info, tm);
+	else
+		ret = -ENOMEM;
+
 	write_unlock(&eb->fs_info->tree_mod_log_lock);
 	if (ret)
 		kfree(tm);
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-09-29 10:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-29  6:56 [PATCH] btrfs: reorganize error handling in btrfs_tree_mod_log_insert_key Sun YangKai
2025-09-29  7:54 ` Qu Wenruo
2025-09-29  8:25   ` Sun YangKai
2025-09-29  8:32     ` Filipe Manana
2025-09-29  8:43       ` Qu Wenruo
2025-09-29  8:30 ` Filipe Manana
2025-09-29 10:24   ` Sun YangKai
2025-09-29 10:41     ` Filipe Manana

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.