From: Qu Wenruo <wqu@suse.com>
To: Sun YangKai <sunk67188@gmail.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: reorganize error handling in btrfs_tree_mod_log_insert_key
Date: Mon, 29 Sep 2025 17:24:26 +0930 [thread overview]
Message-ID: <eb37da47-2a32-4ff1-9c63-b97a69cc019d@suse.com> (raw)
In-Reply-To: <20250929065802.2748-1-sunk67188@gmail.com>
在 2025/9/29 16:26, 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);
Sorry, I don't think this is really that better.
In fact I'm wondering why we don't delay the allocation after
tree_mod_dont_log()?
That would be way more straightforward.
Thanks,
Qu
> + else
> + ret = -ENOMEM;
> +
> write_unlock(&eb->fs_info->tree_mod_log_lock);
> if (ret)
> kfree(tm);
next prev parent reply other threads:[~2025-09-29 7:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=eb37da47-2a32-4ff1-9c63-b97a69cc019d@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=sunk67188@gmail.com \
/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.