Skip to content

Commit fdba66e

Browse files
committed
btrfs: avoid transaction commit on error in insert_balance_item()
There's no point in committing the transaction if we failed to insert the balance item, since we haven't done anything else after we started/joined the transaction. Also stop using two variables for tracking the return value and use only 'ret'. Reviewed-by: Daniel Vacek <neelx@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com>
1 parent 217b58b commit fdba66e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

fs/btrfs/volumes.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3642,7 +3642,7 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
36423642
struct btrfs_path *path;
36433643
struct extent_buffer *leaf;
36443644
struct btrfs_key key;
3645-
int ret, err;
3645+
int ret;
36463646

36473647
path = btrfs_alloc_path();
36483648
if (!path)
@@ -3677,9 +3677,11 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
36773677
btrfs_set_balance_flags(leaf, item, bctl->flags);
36783678
out:
36793679
btrfs_free_path(path);
3680-
err = btrfs_commit_transaction(trans);
3681-
if (err && !ret)
3682-
ret = err;
3680+
if (ret == 0)
3681+
ret = btrfs_commit_transaction(trans);
3682+
else
3683+
btrfs_end_transaction(trans);
3684+
36833685
return ret;
36843686
}
36853687

0 commit comments

Comments
 (0)