Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

btrfs: fix silent failure when deleting root reference

At btrfs_del_root_ref(), if btrfs_search_slot() returns an error, we end
up returning from the function with a value of 0 (success). This happens
because the function returns the value stored in the variable 'err',
which is 0, while the error value we got from btrfs_search_slot() is
stored in the 'ret' variable.

So fix it by setting 'err' with the error value.

Fixes: 8289ed9f93bef2 ("btrfs: replace the BUG_ON in btrfs_del_root_ref with proper error handling")
CC: stable@vger.kernel.org # 5.16+
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by

Filipe Manana and committed by
David Sterba
47bf225a ced8ecf0

+3 -2
+3 -2
fs/btrfs/root-tree.c
··· 349 349 key.offset = ref_id; 350 350 again: 351 351 ret = btrfs_search_slot(trans, tree_root, &key, path, -1, 1); 352 - if (ret < 0) 352 + if (ret < 0) { 353 + err = ret; 353 354 goto out; 354 - if (ret == 0) { 355 + } else if (ret == 0) { 355 356 leaf = path->nodes[0]; 356 357 ref = btrfs_item_ptr(leaf, path->slots[0], 357 358 struct btrfs_root_ref);