Skip to content

Commit 140ac52

Browse files
Sun YangKaikdave
authored andcommitted
btrfs: simplify the return value handling in search_ioctl()
Move the assignment of -EFAULT to within the error condition check in fault_in_subpage_writeable(). The previous placement outside the condition could lead to the error value being overwritten by subsequent assignments, cause unnecessary assignments. Simplify loop exit logic by removing redundant goto. The original code used 'goto err' to bypass post-loop processing after handling errors from btrfs_search_forward(). However, the loop's termination naturally falls through to the post-loop section, which already handles 'ret' values. Replacing 'goto err' with 'break' eliminates redundant control flow, consolidates error handling, and makes the loop's exit conditions explicit. Signed-off-by: Sun YangKai <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 009ca35 commit 140ac52

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

fs/btrfs/ioctl.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,31 +1641,30 @@ static noinline int search_ioctl(struct btrfs_root *root,
16411641
key.offset = sk->min_offset;
16421642

16431643
while (1) {
1644-
ret = -EFAULT;
16451644
/*
16461645
* Ensure that the whole user buffer is faulted in at sub-page
16471646
* granularity, otherwise the loop may live-lock.
16481647
*/
1649-
if (fault_in_subpage_writeable(ubuf + sk_offset,
1650-
*buf_size - sk_offset))
1648+
if (fault_in_subpage_writeable(ubuf + sk_offset, *buf_size - sk_offset)) {
1649+
ret = -EFAULT;
16511650
break;
1651+
}
16521652

16531653
ret = btrfs_search_forward(root, &key, path, sk->min_transid);
1654-
if (ret != 0) {
1655-
if (ret > 0)
1656-
ret = 0;
1657-
goto err;
1658-
}
1654+
if (ret)
1655+
break;
1656+
16591657
ret = copy_to_sk(path, &key, sk, buf_size, ubuf,
16601658
&sk_offset, &num_found);
16611659
btrfs_release_path(path);
16621660
if (ret)
16631661
break;
16641662

16651663
}
1664+
/* Normalize return values from btrfs_search_forward() and copy_to_sk(). */
16661665
if (ret > 0)
16671666
ret = 0;
1668-
err:
1667+
16691668
sk->nr_items = num_found;
16701669
btrfs_put_root(root);
16711670
btrfs_free_path(path);

0 commit comments

Comments
 (0)