Skip to content

Commit 1618aa3

Browse files
asjkdave
authored andcommitted
btrfs: simplify return variables in lookup_extent_data_ref()
First, drop err instead reuse ret, choose to return the error instead of goto fail and then return the same error. Do not initialize the ret until where it has to be initialized. Slight logic change in handling the btrfs_search_slot() and btrfs_next_leaf() return value. Signed-off-by: Anand Jain <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 6e812a9 commit 1618aa3

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

fs/btrfs/extent-tree.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,8 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,
446446
struct btrfs_extent_data_ref *ref;
447447
struct extent_buffer *leaf;
448448
u32 nritems;
449-
int ret;
450449
int recow;
451-
int err = -ENOENT;
450+
int ret;
452451

453452
key.objectid = bytenr;
454453
if (parent) {
@@ -462,26 +461,26 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,
462461
again:
463462
recow = 0;
464463
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
465-
if (ret < 0) {
466-
err = ret;
467-
goto fail;
468-
}
464+
if (ret < 0)
465+
return ret;
469466

470467
if (parent) {
471-
if (!ret)
472-
return 0;
473-
goto fail;
468+
if (ret)
469+
return -ENOENT;
470+
return 0;
474471
}
475472

473+
ret = -ENOENT;
476474
leaf = path->nodes[0];
477475
nritems = btrfs_header_nritems(leaf);
478476
while (1) {
479477
if (path->slots[0] >= nritems) {
480478
ret = btrfs_next_leaf(root, path);
481-
if (ret < 0)
482-
err = ret;
483-
if (ret)
484-
goto fail;
479+
if (ret) {
480+
if (ret > 1)
481+
return -ENOENT;
482+
return ret;
483+
}
485484

486485
leaf = path->nodes[0];
487486
nritems = btrfs_header_nritems(leaf);
@@ -502,13 +501,13 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,
502501
btrfs_release_path(path);
503502
goto again;
504503
}
505-
err = 0;
504+
ret = 0;
506505
break;
507506
}
508507
path->slots[0]++;
509508
}
510509
fail:
511-
return err;
510+
return ret;
512511
}
513512

514513
static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans,

0 commit comments

Comments
 (0)