btrfs: move transaction aborts to the error site in add_block_group_free_space()
authorDavid Sterba <dsterba@suse.com>
Sat, 17 May 2025 19:03:57 +0000 (21:03 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Jul 2025 21:50:34 +0000 (23:50 +0200)
Transaction aborts should be done next to the place the error happens,
which was not done in add_block_group_free_space().

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/free-space-tree.c

index 0755656a270eecf5dd0ba8522363b76fea354ea3..9eb9858e8e995a159cb82310db6f32a548e1aa7f 100644 (file)
@@ -1456,16 +1456,17 @@ int add_block_group_free_space(struct btrfs_trans_handle *trans,
        path = btrfs_alloc_path();
        if (!path) {
                ret = -ENOMEM;
+               btrfs_abort_transaction(trans, ret);
                goto out;
        }
 
        ret = __add_block_group_free_space(trans, block_group, path);
+       if (ret)
+               btrfs_abort_transaction(trans, ret);
 
 out:
        btrfs_free_path(path);
        mutex_unlock(&block_group->free_space_lock);
-       if (ret)
-               btrfs_abort_transaction(trans, ret);
        return ret;
 }