aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Filipe Manana <fdmanana@suse.com> 2024-04-11 18:39:51 +0100
committerGravatar David Sterba <dsterba@suse.com> 2024-05-07 21:31:03 +0200
commitfb90e1caf00d0797d355c8f15d004e41edf22e96 (patch)
tree4fd2bf5a21178948c094c3912af74f01640b0f9b
parentbtrfs: remove use of a temporary list at btrfs_lookup_csums_list() (diff)
downloadlinux-fb90e1caf00d0797d355c8f15d004e41edf22e96.tar.gz
linux-fb90e1caf00d0797d355c8f15d004e41edf22e96.tar.bz2
linux-fb90e1caf00d0797d355c8f15d004e41edf22e96.zip
btrfs: simplify error path for btrfs_lookup_csums_list()
In the error path we have this while loop that keeps iterating over the csums of the list and then delete them from the list and free them, testing for an error (ret < 0) and list emptyness as the conditions of the while loop. Simplify this by using list_for_each_entry_safe() so there's no need to delete elements from the list and need to test the error condition on each iteration. Also rename the 'fail' label to 'out' since the label is not exclusive to a failure path, as we also end up there when the function succeeds, and it's also a more common label name. 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>
-rw-r--r--fs/btrfs/file-item.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index c2799325706f..231abcc87f63 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -487,7 +487,7 @@ int btrfs_lookup_csums_list(struct btrfs_root *root, u64 start, u64 end,
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0)
- goto fail;
+ goto out;
if (ret > 0 && path->slots[0] > 0) {
leaf = path->nodes[0];
btrfs_item_key_to_cpu(leaf, &key, path->slots[0] - 1);
@@ -522,7 +522,7 @@ int btrfs_lookup_csums_list(struct btrfs_root *root, u64 start, u64 end,
if (path->slots[0] >= btrfs_header_nritems(leaf)) {
ret = btrfs_next_leaf(root, path);
if (ret < 0)
- goto fail;
+ goto out;
if (ret > 0)
break;
leaf = path->nodes[0];
@@ -557,7 +557,7 @@ int btrfs_lookup_csums_list(struct btrfs_root *root, u64 start, u64 end,
GFP_NOFS);
if (!sums) {
ret = -ENOMEM;
- goto fail;
+ goto out;
}
sums->logical = start;
@@ -576,11 +576,12 @@ int btrfs_lookup_csums_list(struct btrfs_root *root, u64 start, u64 end,
path->slots[0]++;
}
ret = 0;
-fail:
- while (ret < 0 && !list_empty(list)) {
- sums = list_entry(list->next, struct btrfs_ordered_sum, list);
- list_del(&sums->list);
- kfree(sums);
+out:
+ if (ret < 0) {
+ struct btrfs_ordered_sum *tmp_sums;
+
+ list_for_each_entry_safe(sums, tmp_sums, list, list)
+ kfree(sums);
}
btrfs_free_path(path);