From: Sun YangKai <sunk67188@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Sun YangKai <sunk67188@gmail.com>
Subject: [PATCH 2/2] btrfs: simplify boolean argument for btrfs_{inc,dec}_ref
Date: Thu, 20 Nov 2025 22:19:14 +0800 [thread overview]
Message-ID: <20251120141948.5323-3-sunk67188@gmail.com> (raw)
In-Reply-To: <20251120141948.5323-1-sunk67188@gmail.com>
Replace open-coded if/else blocks with the boolean expression
directly, making the code shorter and easier to read.
No functional change.
Signed-off-by: Sun YangKai <sunk67188@gmail.com>
---
fs/btrfs/ctree.c | 25 +++++++------------------
fs/btrfs/extent-tree.c | 17 +++++------------
2 files changed, 12 insertions(+), 30 deletions(-)
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 1b15cef86cbc..e056dedec221 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -291,15 +291,9 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
return ret;
}
- if (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID) {
- ret = btrfs_inc_ref(trans, root, cow, true);
- if (unlikely(ret))
- btrfs_abort_transaction(trans, ret);
- } else {
- ret = btrfs_inc_ref(trans, root, cow, false);
- if (unlikely(ret))
- btrfs_abort_transaction(trans, ret);
- }
+ ret = btrfs_inc_ref(trans, root, cow, new_root_objectid == BTRFS_TREE_RELOC_OBJECTID);
+ if (unlikely(ret))
+ btrfs_abort_transaction(trans, ret);
if (ret) {
btrfs_tree_unlock(cow);
free_extent_buffer(cow);
@@ -437,20 +431,15 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
if (ret)
return ret;
} else {
-
- if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID)
- ret = btrfs_inc_ref(trans, root, cow, true);
- else
- ret = btrfs_inc_ref(trans, root, cow, false);
+ ret = btrfs_inc_ref(trans, root, cow,
+ btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID);
if (ret)
return ret;
}
} else {
if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
- if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID)
- ret = btrfs_inc_ref(trans, root, cow, true);
- else
- ret = btrfs_inc_ref(trans, root, cow, false);
+ ret = btrfs_inc_ref(trans, root, cow,
+ btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID);
if (ret)
return ret;
ret = btrfs_dec_ref(trans, root, buf, true);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 527310f3aeb3..8e6f362de649 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5875,18 +5875,11 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans,
if (wc->refs[level] == 1) {
if (level == 0) {
- if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
- ret = btrfs_dec_ref(trans, root, eb, true);
- if (ret) {
- btrfs_abort_transaction(trans, ret);
- return ret;
- }
- } else {
- ret = btrfs_dec_ref(trans, root, eb, false);
- if (unlikely(ret)) {
- btrfs_abort_transaction(trans, ret);
- return ret;
- }
+ ret = btrfs_dec_ref(trans, root, eb,
+ !!(wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF));
+ if (unlikely(ret)) {
+ btrfs_abort_transaction(trans, ret);
+ return ret;
}
if (btrfs_is_fstree(btrfs_root_id(root))) {
ret = btrfs_qgroup_trace_leaf_items(trans, eb);
--
2.51.2
next prev parent reply other threads:[~2025-11-20 14:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-20 14:19 [PATCH 0/2] btrfs: use true/false and simplify boolean parameters in btrfs_{inc,dec}_ref Sun YangKai
2025-11-20 14:19 ` [PATCH 1/2] btrfs: use true/false for " Sun YangKai
2025-11-21 6:59 ` Johannes Thumshirn
2025-11-20 14:19 ` Sun YangKai [this message]
2025-11-20 19:02 ` [PATCH 2/2] btrfs: simplify boolean argument for btrfs_{inc,dec}_ref David Sterba
2025-11-21 3:17 ` Sun Yangkai
2025-11-21 6:58 ` Johannes Thumshirn
2025-11-21 14:47 ` David Sterba
2025-11-21 7:21 ` Daniel Vacek
2025-11-20 19:00 ` [PATCH 0/2] btrfs: use true/false and simplify boolean parameters in btrfs_{inc,dec}_ref Boris Burkov
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=20251120141948.5323-3-sunk67188@gmail.com \
--to=sunk67188@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox