* [PATCH v2] btrfs: fix memory leaks when rejecting a non SINGLE data profile without an RST
@ 2025-10-08 7:40 Miquel Sabaté Solà
2025-10-08 12:04 ` Johannes Thumshirn
0 siblings, 1 reply; 3+ messages in thread
From: Miquel Sabaté Solà @ 2025-10-08 7:40 UTC (permalink / raw)
To: linux-btrfs
Cc: clm, dsterba, naohiro.aota, boris, johannes.thumshirn,
linux-kernel, Miquel Sabaté Solà
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, we set the ret
value and fall through the rest of the cleanup code.
Fixes: 5906333cc4af ("btrfs: zoned: don't skip block group profile checks on conventional zones")
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
---
fs/btrfs/zoned.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index e3341a84f4ab..8f767a6cd49b 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1753,7 +1753,11 @@ 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;
+ /*
+ * Note that this might be overwritten by later if statements,
+ * but the error will be at least printed by the line above.
+ */
+ ret = -EINVAL;
}
if (unlikely(cache->alloc_offset > cache->zone_capacity)) {
@@ -1785,6 +1789,7 @@ 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;
}
+
bitmap_free(active);
kfree(zone_info);
--
2.51.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] btrfs: fix memory leaks when rejecting a non SINGLE data profile without an RST
2025-10-08 7:40 [PATCH v2] btrfs: fix memory leaks when rejecting a non SINGLE data profile without an RST Miquel Sabaté Solà
@ 2025-10-08 12:04 ` Johannes Thumshirn
2025-10-08 12:15 ` Miquel Sabaté Solà
0 siblings, 1 reply; 3+ messages in thread
From: Johannes Thumshirn @ 2025-10-08 12:04 UTC (permalink / raw)
To: Miquel Sabaté Solà, linux-btrfs@vger.kernel.org
Cc: clm@fb.com, dsterba@suse.com, Naohiro Aota, boris@bur.io,
linux-kernel@vger.kernel.org
On 10/8/25 9:41 AM, Miquel Sabaté Solà wrote:
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index e3341a84f4ab..8f767a6cd49b 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -1753,7 +1753,11 @@ 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;
> + /*
> + * Note that this might be overwritten by later if statements,
> + * but the error will be at least printed by the line above.
> + */
Not convinced the comment is useful.
> + ret = -EINVAL;
> }
>
> if (unlikely(cache->alloc_offset > cache->zone_capacity)) {
> @@ -1785,6 +1789,7 @@ 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;
> }
> +
> bitmap_free(active);
> kfree(zone_info);
>
Stray newline.
Other than that,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] btrfs: fix memory leaks when rejecting a non SINGLE data profile without an RST
2025-10-08 12:04 ` Johannes Thumshirn
@ 2025-10-08 12:15 ` Miquel Sabaté Solà
0 siblings, 0 replies; 3+ messages in thread
From: Miquel Sabaté Solà @ 2025-10-08 12:15 UTC (permalink / raw)
To: Johannes Thumshirn
Cc: linux-btrfs@vger.kernel.org, clm@fb.com, dsterba@suse.com,
Naohiro Aota, boris@bur.io, linux-kernel@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 1302 bytes --]
Johannes Thumshirn @ 2025-10-08 12:04 GMT:
> On 10/8/25 9:41 AM, Miquel Sabaté Solà wrote:
>> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
>> index e3341a84f4ab..8f767a6cd49b 100644
>> --- a/fs/btrfs/zoned.c
>> +++ b/fs/btrfs/zoned.c
>> @@ -1753,7 +1753,11 @@ 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;
>> + /*
>> + * Note that this might be overwritten by later if statements,
>> + * but the error will be at least printed by the line above.
>> + */
>
>
> Not convinced the comment is useful.
>
>> + ret = -EINVAL;
>> }
>>
>> if (unlikely(cache->alloc_offset > cache->zone_capacity)) {
>> @@ -1785,6 +1789,7 @@ 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;
>> }
>> +
>> bitmap_free(active);
>> kfree(zone_info);
>>
>
>
> Stray newline.
>
> Other than that,
>
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Thanks for the review! Let me send a v3 shortly with your comments
applied.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 897 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-08 12:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-08 7:40 [PATCH v2] btrfs: fix memory leaks when rejecting a non SINGLE data profile without an RST Miquel Sabaté Solà
2025-10-08 12:04 ` Johannes Thumshirn
2025-10-08 12:15 ` Miquel Sabaté Solà
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).