From: Sun YangKai <sunk67188@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Sun YangKai <sunk67188@gmail.com>
Subject: [PATCH] btrfs: reorganize error handling in btrfs_tree_mod_log_insert_key
Date: Mon, 29 Sep 2025 14:56:29 +0800 [thread overview]
Message-ID: <20250929065802.2748-1-sunk67188@gmail.com> (raw)
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
next reply other threads:[~2025-09-29 6:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-29 6:56 Sun YangKai [this message]
2025-09-29 7:54 ` [PATCH] btrfs: reorganize error handling in btrfs_tree_mod_log_insert_key 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250929065802.2748-1-sunk67188@gmail.com \
--to=sunk67188@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.