Skip to contentSkip to conversation

btrfs: fix memory leaks when rejecting a non SINGLE data profile without an RST

PATCH Superseded Miquel Sabaté Solà 2 participants 3 messages Oct 8, 2025 Btrfs file system

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 btrfs: fix memory leaks when rejecting a non SINGLE data profile without an RST

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")
---
 fs/btrfs/zoned.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/btrfs/zoned.c +6 -1
index e3341a84f4ab..8f767a6cd49b 100644
@@ -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);
 
Signature · 1 line
2.51.0
Reviewed-by on v2 1/1
#1 lore raw

fs/btrfs/zoned.c int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) · line 1759

Quoted 13 lines · Miquel Sabaté Solà
fs/btrfs/zoned.c +4 -1
index e3341a84f4ab..8f767a6cd49b 100644
@@ -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.

fs/btrfs/zoned.c int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) · line 1795

Quoted 12 lines
fs/btrfs/zoned.c +2 -0
+		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,

#2 lore raw

Johannes Thumshirn @ 2025-10-08 12:04 GMT:

Quoted 34 lines · Miquel Sabaté Solà

fs/btrfs/zoned.c int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) · line 1759

Quoted 13 lines
fs/btrfs/zoned.c +4 -1
index e3341a84f4ab..8f767a6cd49b 100644
@@ -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.

fs/btrfs/zoned.c int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) · line 1795

Quoted 12 lines
fs/btrfs/zoned.c +2 -0
+		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.

Quoted 3 lines

Other than that,

Thanks for the review! Let me send a v3 shortly with your comments applied.