Skip to content

Commit 1fdbd03

Browse files
fdmananakdave
authored andcommitted
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 <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 48ff708 commit 1fdbd03

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

fs/btrfs/root-tree.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ int btrfs_del_root_ref(struct btrfs_trans_handle *trans, u64 root_id,
337337
struct extent_buffer *leaf;
338338
struct btrfs_key key;
339339
unsigned long ptr;
340-
int err = 0;
341340
int ret;
342341

343342
path = btrfs_alloc_path();
@@ -350,7 +349,6 @@ int btrfs_del_root_ref(struct btrfs_trans_handle *trans, u64 root_id,
350349
again:
351350
ret = btrfs_search_slot(trans, tree_root, &key, path, -1, 1);
352351
if (ret < 0) {
353-
err = ret;
354352
goto out;
355353
} else if (ret == 0) {
356354
leaf = path->nodes[0];
@@ -360,18 +358,18 @@ int btrfs_del_root_ref(struct btrfs_trans_handle *trans, u64 root_id,
360358
if ((btrfs_root_ref_dirid(leaf, ref) != dirid) ||
361359
(btrfs_root_ref_name_len(leaf, ref) != name_len) ||
362360
memcmp_extent_buffer(leaf, name, ptr, name_len)) {
363-
err = -ENOENT;
361+
ret = -ENOENT;
364362
goto out;
365363
}
366364
*sequence = btrfs_root_ref_sequence(leaf, ref);
367365

368366
ret = btrfs_del_item(trans, tree_root, path);
369-
if (ret) {
370-
err = ret;
367+
if (ret)
371368
goto out;
372-
}
373-
} else
374-
err = -ENOENT;
369+
} else {
370+
ret = -ENOENT;
371+
goto out;
372+
}
375373

376374
if (key.type == BTRFS_ROOT_BACKREF_KEY) {
377375
btrfs_release_path(path);
@@ -383,7 +381,7 @@ int btrfs_del_root_ref(struct btrfs_trans_handle *trans, u64 root_id,
383381

384382
out:
385383
btrfs_free_path(path);
386-
return err;
384+
return ret;
387385
}
388386

389387
/*

0 commit comments

Comments
 (0)