From: Johannes Thumshirn <Johannes.Thumshirn@wdc.com>
To: "Miquel Sabaté Solà" <mssola@mssola.com>,
"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Cc: "clm@fb.com" <clm@fb.com>, "dsterba@suse.com" <dsterba@suse.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] btrfs: fix memory leak when rejecting a non SINGLE data profile without an RST
Date: Tue, 7 Oct 2025 10:13:18 +0000 [thread overview]
Message-ID: <e82bb44e-5f56-4ddc-976a-9ff268a5b705@wdc.com> (raw)
In-Reply-To: <20251007055453.343450-1-mssola@mssola.com>
On 10/7/25 7:55 AM, Miquel Sabaté Solà wrote:
> At the end of btrfs_load_block_group_zone_info() the first thing we do
> is to ensure that if the mapping type is not a SINGLE one and there is
> no RAID stripe tree, then we return early with an error.
>
> Doing that, though, prevents the code from running the last calls from
> this function which are about freeing memory allocated during its
> run. Hence, in this case, instead of returning early go to the freeing
> section of this function and leave then.
>
> Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
> ---
> fs/btrfs/zoned.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index e3341a84f4ab..b0f5d61dbfd2 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -1753,7 +1753,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
> !fs_info->stripe_root) {
> btrfs_err(fs_info, "zoned: data %s needs raid-stripe-tree",
> btrfs_bg_type_to_raid_name(map->type));
> - return -EINVAL;
> + ret = -EINVAL;
> + goto out_free;
> }
>
> if (unlikely(cache->alloc_offset > cache->zone_capacity)) {
> @@ -1785,6 +1786,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
> btrfs_free_chunk_map(cache->physical_map);
> cache->physical_map = NULL;
> }
> +
> +out_free:
> bitmap_free(active);
> kfree(zone_info);
>
Wouldn't it make more sense to only set "ret = -EINVAL" and run the rest
of the functions cleanup? I.e. with your patch the chunk_map isn't freed
as well.
next prev parent reply other threads:[~2025-10-07 10:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-07 5:54 Miquel Sabaté Solà
2025-10-07 10:13 ` Johannes Thumshirn [this message]
2025-10-07 11:04 ` Miquel Sabaté Solà
[not found] ` <0a87083a-cfef-4cf5-a73f-465797fa5759@wdc.com>
2025-10-07 12:04 ` Miquel Sabaté Solà
2025-10-07 12:14 ` Johannes Thumshirn
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=e82bb44e-5f56-4ddc-976a-9ff268a5b705@wdc.com \
--to=johannes.thumshirn@wdc.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mssola@mssola.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®