From: Qu Wenruo <wqu@suse.com>
To: Gladyshev Ilya <foxido@foxido.dev>
Cc: Chris Mason <clm@fb.com>, David Sterba <dsterba@suse.com>,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 2/8] btrfs: move kfree out of btrfs_create_qgroup's cleanup path
Date: Thu, 13 Nov 2025 07:00:53 +1030 [thread overview]
Message-ID: <74034783-1715-4020-a22b-45db6cd389be@suse.com> (raw)
In-Reply-To: <79f3f83eb5f693ad88b0cad9d37e2db214ba1491.1762972845.git.foxido@foxido.dev>
在 2025/11/13 05:19, Gladyshev Ilya 写道:
> Relocate kfree() from the generic cleanup path to the specific error
> exit where the allocation could leak. This prepares for future
> simplification by allowing removal of the 'out' label and use of
> mutex_guard for cleaner resource management.
>
> Signed-off-by: Gladyshev Ilya <foxido@foxido.dev>
> ---
> fs/btrfs/qgroup.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index 9904bcfd3a60..a8474d0a9c58 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -1659,7 +1659,7 @@ int btrfs_create_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid)
> struct btrfs_fs_info *fs_info = trans->fs_info;
> struct btrfs_root *quota_root;
> struct btrfs_qgroup *qgroup;
> - struct btrfs_qgroup *prealloc = NULL;
> + struct btrfs_qgroup *prealloc;
> int ret = 0;
>
> mutex_lock(&fs_info->qgroup_ioctl_lock);
> @@ -1681,18 +1681,18 @@ int btrfs_create_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid)
> }
>
> ret = add_qgroup_item(trans, quota_root, qgroupid);
> - if (ret)
> + if (ret) {
> + kfree(prealloc);
> goto out;
> + }
>
> spin_lock(&fs_info->qgroup_lock);
> qgroup = add_qgroup_rb(fs_info, prealloc, qgroupid);
> spin_unlock(&fs_info->qgroup_lock);
> - prealloc = NULL;
>
> ret = btrfs_sysfs_add_one_qgroup(fs_info, qgroup);
> out:
> mutex_unlock(&fs_info->qgroup_ioctl_lock);
You're not on the latest for-next branch, which has the following patch
applied doing the extra sanity checks:
https://lore.kernel.org/linux-btrfs/20251024102143.236665-5-mssola@mssola.com/
With the extra ASSERT()s, the old code makes more sense.
Thanks,
Qu
> - kfree(prealloc);
> return ret;
> }
>
next prev parent reply other threads:[~2025-11-12 20:30 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-12 18:49 [RFC PATCH 0/8] use cleanup.h in btrfs Gladyshev Ilya
2025-11-12 18:49 ` [RFC PATCH 1/8] btrfs: remove redundant label in __del_qgroup_relation Gladyshev Ilya
2025-11-12 18:49 ` [RFC PATCH 2/8] btrfs: move kfree out of btrfs_create_qgroup's cleanup path Gladyshev Ilya
2025-11-12 20:30 ` Qu Wenruo [this message]
2025-11-12 18:49 ` [RFC PATCH 3/8] btrfs: simplify control flow in scrub_simple_mirror Gladyshev Ilya
2025-11-12 18:49 ` [RFC PATCH 4/8] btrfs: simplify function protections with guards Gladyshev Ilya
2025-11-13 8:43 ` David Sterba
2025-11-13 10:06 ` Gladyshev Ilya
2025-11-13 11:25 ` David Sterba
2025-11-13 12:30 ` Daniel Vacek
2025-11-12 18:49 ` [RFC PATCH 5/8] btrfs: use cleanup.h guard()s to simplify unlocks on return Gladyshev Ilya
2025-11-12 18:49 ` [RFC PATCH 6/8] btrfs: simplify cleanup via scoped_guard() Gladyshev Ilya
2025-11-13 8:48 ` David Sterba
2025-11-12 18:49 ` [RFC PATCH 7/8] btrfs: simplify return path via cleanup.h Gladyshev Ilya
2025-11-12 20:50 ` Qu Wenruo
2025-11-13 8:54 ` David Sterba
2025-11-13 12:48 ` Daniel Vacek
2025-11-12 18:49 ` [RFC PATCH 8/8] btrfs: simplify cleanup in btrfs_add_qgroup_relation Gladyshev Ilya
2025-11-12 20:46 ` Qu Wenruo
2025-11-12 20:55 ` [RFC PATCH 0/8] use cleanup.h in btrfs Qu Wenruo
2025-11-13 8:01 ` Gladyshev Ilya
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=74034783-1715-4020-a22b-45db6cd389be@suse.com \
--to=wqu@suse.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=foxido@foxido.dev \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox