Skip to contentSkip to conversation

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

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

lore
Share & tools
lore
#0 lore raw

PATCH v3 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")

---
Changes in v3:
- Remove comment which was deemed unnecessary.

Changes in v2:
- Change 'goto' to just assigning the 'ret' variable and falling through.

 fs/btrfs/zoned.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/zoned.c +1 -1
index e3341a84f4ab..838149fa60ce 100644
@@ -1753,7 +1753,7 @@ 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;
 	}
 
 	if (unlikely(cache->alloc_offset > cache->zone_capacity)) {

--
2.51.0

#1 lore raw
Quoted 36 lines · 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")

---
Changes in v3:
- Remove comment which was deemed unnecessary.

Changes in v2:
- Change 'goto' to just assigning the 'ret' variable and falling through.

  fs/btrfs/zoned.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/zoned.c +1 -2
index e3341a84f4ab..838149fa60ce 100644
@@ -1753,7 +1753,7 @@ 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;
  	}
 
  	if (unlikely(cache->alloc_offset > cache->zone_capacity)) {
--
Quoted 3 lines

2.51.0

Applied, thanks.