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

btrfs: simplify error handling at btrfs_del_root_ref()

At btrfs_del_root_ref() we are using two return variables, named 'ret'
and 'err'. This makes it harder to follow and easier to return the wrong
value in case an error happens - the previous patch in the series, which
has the subject "btrfs: fix silent failure when deleting root
reference", fixed a bug due to confusion created by these two variables.

So change the function to use a single variable for tracking the return
value of the function, using only 'ret', which is consistent with most
of the codebase.

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
1fdbd03d 48ff7083

+7 -9
+7 -9
fs/btrfs/root-tree.c
··· 337 337 struct extent_buffer *leaf; 338 338 struct btrfs_key key; 339 339 unsigned long ptr; 340 - int err = 0; 341 340 int ret; 342 341 343 342 path = btrfs_alloc_path(); ··· 349 350 again: 350 351 ret = btrfs_search_slot(trans, tree_root, &key, path, -1, 1); 351 352 if (ret < 0) { 352 - err = ret; 353 353 goto out; 354 354 } else if (ret == 0) { 355 355 leaf = path->nodes[0]; ··· 358 360 if ((btrfs_root_ref_dirid(leaf, ref) != dirid) || 359 361 (btrfs_root_ref_name_len(leaf, ref) != name_len) || 360 362 memcmp_extent_buffer(leaf, name, ptr, name_len)) { 361 - err = -ENOENT; 363 + ret = -ENOENT; 362 364 goto out; 363 365 } 364 366 *sequence = btrfs_root_ref_sequence(leaf, ref); 365 367 366 368 ret = btrfs_del_item(trans, tree_root, path); 367 - if (ret) { 368 - err = ret; 369 + if (ret) 369 370 goto out; 370 - } 371 - } else 372 - err = -ENOENT; 371 + } else { 372 + ret = -ENOENT; 373 + goto out; 374 + } 373 375 374 376 if (key.type == BTRFS_ROOT_BACKREF_KEY) { 375 377 btrfs_release_path(path); ··· 381 383 382 384 out: 383 385 btrfs_free_path(path); 384 - return err; 386 + return ret; 385 387 } 386 388 387 389 /*