public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: George Hu <integral@archlinux.org>
To: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>, George Hu <integral@archlinux.org>
Subject: [PATCH] btrfs: use in_range() macro in volumes.c
Date: Sun, 29 Jun 2025 13:04:25 +0800	[thread overview]
Message-ID: <20250629050425.139456-1-integral@archlinux.org> (raw)

Replace "if (start <= val && val < (start + len))" in volumes.c
with in_range() macro to improve code readability.

Signed-off-by: George Hu <integral@archlinux.org>
---
 fs/btrfs/volumes.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index f475b4b7c457..c5479dce0cb2 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -3198,7 +3198,7 @@ struct btrfs_chunk_map *btrfs_get_chunk_map(struct btrfs_fs_info *fs_info,
 		return ERR_PTR(-EINVAL);
 	}
 
-	if (unlikely(map->start > logical || map->start + map->chunk_len <= logical)) {
+	if (unlikely(!in_range(logical, map->start, map->chunk_len))) {
 		btrfs_crit(fs_info,
 			   "found a bad chunk map, wanted %llu-%llu, found %llu-%llu",
 			   logical, logical + length, map->start,
@@ -3841,7 +3841,7 @@ static bool chunk_usage_range_filter(struct btrfs_fs_info *fs_info, u64 chunk_of
 	else
 		user_thresh_max = mult_perc(cache->length, bargs->usage_max);
 
-	if (user_thresh_min <= chunk_used && chunk_used < user_thresh_max)
+	if (in_range(chunk_used, user_thresh_min, user_thresh_max))
 		ret = false;
 
 	btrfs_put_block_group(cache);
@@ -6211,9 +6211,7 @@ struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info,
 			if (i < sub_stripes)
 				stripes[i].length -= stripe_offset;
 
-			if (stripe_index >= last_stripe &&
-			    stripe_index <= (last_stripe +
-					     sub_stripes - 1))
+			if (in_range(stripe_index, last_stripe, sub_stripes))
 				stripes[i].length -= stripe_end_offset;
 
 			if (i == sub_stripes - 1)
@@ -7047,11 +7045,10 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,
 	map = btrfs_find_chunk_map(fs_info, logical, 1);
 
 	/* already mapped? */
-	if (map && map->start <= logical && map->start + map->chunk_len > logical) {
-		btrfs_free_chunk_map(map);
-		return 0;
-	} else if (map) {
+	if (map) {
 		btrfs_free_chunk_map(map);
+		if (in_range(logical, map->start, map->chunk_len))
+			return 0;
 	}
 
 	map = btrfs_alloc_chunk_map(num_stripes, GFP_NOFS);
@@ -8239,8 +8236,7 @@ static void map_raid56_repair_block(struct btrfs_io_context *bioc,
 		u64 stripe_start = bioc->full_stripe_logical +
 				   btrfs_stripe_nr_to_offset(i);
 
-		if (logical >= stripe_start &&
-		    logical < stripe_start + BTRFS_STRIPE_LEN)
+		if (in_range(logical, stripe_start, BTRFS_STRIPE_LEN))
 			break;
 	}
 	ASSERT(i < data_stripes, "i=%d data_stripes=%d", i, data_stripes);
-- 
2.50.0


             reply	other threads:[~2025-06-29  5:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-29  5:04 George Hu [this message]
2025-06-29  5:23 ` [PATCH] btrfs: use in_range() macro in volumes.c Qu Wenruo

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=20250629050425.139456-1-integral@archlinux.org \
    --to=integral@archlinux.org \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@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