From: Filipe Manana Date: Wed, 17 Dec 2025 15:53:59 +0000 (+0000) Subject: btrfs: avoid transaction commit on error in insert_balance_item() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d206b0c21ef9b230627ff742170130912a1db3a;p=thirdparty%2Fkernel%2Flinux.git 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 Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba --- diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index a89243a57fde4..a541cd30c6b8b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -3644,7 +3644,7 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info, struct btrfs_path *path; struct extent_buffer *leaf; struct btrfs_key key; - int ret, err; + int ret; path = btrfs_alloc_path(); if (!path) @@ -3679,9 +3679,11 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info, btrfs_set_balance_flags(leaf, item, bctl->flags); out: btrfs_free_path(path); - err = btrfs_commit_transaction(trans); - if (err && !ret) - ret = err; + if (ret == 0) + ret = btrfs_commit_transaction(trans); + else + btrfs_end_transaction(trans); + return ret; }