From: Sun YangKai <sunk67188@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.cz>, Sun YangKai <sunk67188@gmail.com>
Subject: [PATCH v2 1/3] btrfs: simplify the return value handling in search_ioctl()
Date: Tue, 11 Mar 2025 16:13:12 +0800 [thread overview]
Message-ID: <20250311081317.13860-2-sunk67188@gmail.com> (raw)
In-Reply-To: <20250311081317.13860-1-sunk67188@gmail.com>
1. Move the assignment of ret = -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.
2. 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.
The changes ensure proper error propagation and make the loop's exit
conditions clearer while maintaining functional equivalence.
Signed-off-by: Sun YangKai <sunk67188@gmail.com>
---
fs/btrfs/ioctl.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 6c18bad53cd3..bef158a1260b 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1642,21 +1642,20 @@ static noinline int search_ioctl(struct inode *inode,
key.offset = sk->min_offset;
while (1) {
- ret = -EFAULT;
/*
* Ensure that the whole user buffer is faulted in at sub-page
* granularity, otherwise the loop may live-lock.
*/
if (fault_in_subpage_writeable(ubuf + sk_offset,
- *buf_size - sk_offset))
+ *buf_size - sk_offset)) {
+ ret = -EFAULT;
break;
+ }
ret = btrfs_search_forward(root, &key, path, sk->min_transid);
- if (ret != 0) {
- if (ret > 0)
- ret = 0;
- goto err;
- }
+ if (ret)
+ break;
+
ret = copy_to_sk(path, &key, sk, buf_size, ubuf,
&sk_offset, &num_found);
btrfs_release_path(path);
@@ -1666,7 +1665,7 @@ static noinline int search_ioctl(struct inode *inode,
}
if (ret > 0)
ret = 0;
-err:
+
sk->nr_items = num_found;
btrfs_put_root(root);
btrfs_free_path(path);
--
2.48.1
next prev parent reply other threads:[~2025-03-11 8:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-11 8:13 [PATCH v2 0/3] btrfs: random code cleanup Sun YangKai
2025-03-11 8:13 ` Sun YangKai [this message]
2025-03-11 8:13 ` [PATCH v2 2/3] btrfs: remove the unnecessary local variable in btrfs_search_forward() Sun YangKai
2025-03-11 8:13 ` [PATCH v2 3/3] btrfs: avoid redundant slot assignment " Sun YangKai
2025-03-11 19:07 ` [PATCH v2 0/3] btrfs: random code cleanup 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=20250311081317.13860-2-sunk67188@gmail.com \
--to=sunk67188@gmail.com \
--cc=dsterba@suse.cz \
--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.