From: David Sterba Date: Tue, 19 Aug 2025 00:16:38 +0000 (-0400) Subject: btrfs: move transaction aborts to the error site in add_block_group_free_space() X-Git-Tag: v6.16.4~246 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a78818390cc072e8bf5596cea821a80e5955c0eb;p=thirdparty%2Fkernel%2Fstable.git btrfs: move transaction aborts to the error site in add_block_group_free_space() [ Upstream commit b63c8c1ede4407835cb8c8bed2014d96619389f3 ] 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 Signed-off-by: David Sterba Stable-dep-of: 1f06c942aa70 ("btrfs: always abort transaction on failure to add block group to free space tree") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c index a83c268f7f87c..11f488c096a6f 100644 --- a/fs/btrfs/free-space-tree.c +++ b/fs/btrfs/free-space-tree.c @@ -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; }