All of lore.kernel.org
 help / color / mirror / Atom feed
From: fdmanana@kernel.org
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 4/6] btrfs: simplify error path for btrfs_lookup_csums_list()
Date: Fri, 12 Apr 2024 16:03:18 +0100	[thread overview]
Message-ID: <d5576134584be460ba386627ee5853fcca5c2edd.1712933006.git.fdmanana@suse.com> (raw)
In-Reply-To: <cover.1712933003.git.fdmanana@suse.com>

From: Filipe Manana <fdmanana@suse.com>

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.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/file-item.c | 17 +++++++++--------
 1 file 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);
-- 
2.43.0


  parent reply	other threads:[~2024-04-12 15:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-12 15:03 [PATCH 0/6] btrfs: some speedup for NOCOW write path and cleanups fdmanana
2024-04-12 15:03 ` [PATCH 1/6] btrfs: add function comment to btrfs_lookup_csums_list() fdmanana
2024-04-13 10:11   ` Qu Wenruo
2024-04-12 15:03 ` [PATCH 2/6] btrfs: remove search_commit parameter from btrfs_lookup_csums_list() fdmanana
2024-04-13 10:10   ` Qu Wenruo
2024-04-12 15:03 ` [PATCH 3/6] btrfs: remove use of a temporary list at btrfs_lookup_csums_list() fdmanana
2024-04-13 10:08   ` Qu Wenruo
2024-04-12 15:03 ` fdmanana [this message]
2024-04-13 10:12   ` [PATCH 4/6] btrfs: simplify error path for btrfs_lookup_csums_list() Qu Wenruo
2024-04-12 15:03 ` [PATCH 5/6] btrfs: make NOCOW checks for existence of checksums in a range more efficient fdmanana
2024-04-13 10:15   ` Qu Wenruo
2024-04-12 15:03 ` [PATCH 6/6] btrfs: open code csum_exist_in_range() fdmanana
2024-04-13 10:16   ` Qu Wenruo
2024-04-12 16:50 ` [PATCH 0/6] btrfs: some speedup for NOCOW write path and cleanups David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d5576134584be460ba386627ee5853fcca5c2edd.1712933006.git.fdmanana@suse.com \
    --to=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.