summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe Manana <fdmanana@suse.com>2025-12-16 11:56:04 +0000
committerDavid Sterba <dsterba@suse.com>2026-02-03 07:49:11 +0100
commit8670a25ecb2fbc35d4e58f8f522e7d5b735d6778 (patch)
tree38010a02883039c831b465588b0450c7d021250a
parentcb73493cae906a7d6668b0e8077eb3a4ef0b2926 (diff)
btrfs: use single return variable in btrfs_find_orphan_roots()
We use both 'ret' and 'err' which is a pattern that generates confusion and resulted in subtle bugs in the past. Remove 'err' and use only 'ret'. Also move simplify the error flow by directly returning from the function instead of breaking of the loop, since there are no resources to cleanup after the loop. Reviewed-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/root-tree.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index 6a7e297ab0a7..a7171112d638 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -217,8 +217,6 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
BTRFS_PATH_AUTO_FREE(path);
struct btrfs_key key;
struct btrfs_root *root;
- int err = 0;
- int ret;
path = btrfs_alloc_path();
if (!path)
@@ -230,20 +228,19 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
while (1) {
u64 root_objectid;
+ int ret;
ret = btrfs_search_slot(NULL, tree_root, &key, path, 0, 0);
- if (ret < 0) {
- err = ret;
- break;
- }
+ if (ret < 0)
+ return ret;
leaf = path->nodes[0];
if (path->slots[0] >= btrfs_header_nritems(leaf)) {
ret = btrfs_next_leaf(tree_root, path);
if (ret < 0)
- err = ret;
- if (ret != 0)
- break;
+ return ret;
+ else if (ret > 0)
+ return 0;
leaf = path->nodes[0];
}
@@ -252,34 +249,33 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
if (key.objectid != BTRFS_ORPHAN_OBJECTID ||
key.type != BTRFS_ORPHAN_ITEM_KEY)
- break;
+ return 0;
root_objectid = key.offset;
key.offset++;
root = btrfs_get_fs_root(fs_info, root_objectid, false);
- err = PTR_ERR_OR_ZERO(root);
- if (err && err != -ENOENT) {
+ ret = PTR_ERR_OR_ZERO(root);
+ if (ret && ret != -ENOENT) {
break;
- } else if (err == -ENOENT) {
+ } else if (ret == -ENOENT) {
struct btrfs_trans_handle *trans;
btrfs_release_path(path);
trans = btrfs_join_transaction(tree_root);
if (IS_ERR(trans)) {
- err = PTR_ERR(trans);
- btrfs_handle_fs_error(fs_info, err,
+ ret = PTR_ERR(trans);
+ btrfs_handle_fs_error(fs_info, ret,
"Failed to start trans to delete orphan item");
- break;
+ return ret;
}
- err = btrfs_del_orphan_item(trans, tree_root,
- root_objectid);
+ ret = btrfs_del_orphan_item(trans, tree_root, root_objectid);
btrfs_end_transaction(trans);
- if (err) {
- btrfs_handle_fs_error(fs_info, err,
+ if (ret) {
+ btrfs_handle_fs_error(fs_info, ret,
"Failed to delete root orphan item");
- break;
+ return ret;
}
continue;
}
@@ -307,7 +303,7 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
btrfs_put_root(root);
}
- return err;
+ return 0;
}
/* drop the root item for 'key' from the tree root */