[PATCH] btrfs: avoid redundant cleanup when device allocation fails

From: Zilin Guan

Date: Thu Nov 06 2025 - 06:58:27 EST


When device allocation fails, the chunk map has not been added to the
mapping tree, so locking for cleanup is unnecessary. Simply free the
chunk map as done when adding it to the mapping tree fails.

Fixes: bf2e2eb060fa2 ("btrfs: Add self-tests for btrfs_rmap_block")
Signed-off-by: Zilin Guan <zilin@xxxxxxxxxx>
---
fs/btrfs/tests/extent-map-tests.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/tests/extent-map-tests.c b/fs/btrfs/tests/extent-map-tests.c
index 42af6c737c6e..e227cfff1e8d 100644
--- a/fs/btrfs/tests/extent-map-tests.c
+++ b/fs/btrfs/tests/extent-map-tests.c
@@ -1036,7 +1036,8 @@ static int test_rmap_block(struct btrfs_fs_info *fs_info,
if (IS_ERR(dev)) {
test_err("cannot allocate device");
ret = PTR_ERR(dev);
- goto out;
+ btrfs_free_chunk_map(map);
+ goto out_free;
}
map->stripes[i].dev = dev;
map->stripes[i].physical = test->data_stripe_phys_start[i];
--
2.34.1