[PATCH v2 3/3] fs:btrfs: Use the new global is_power_of_2_u64() helper

From: David Gow

Date: Sun Aug 30 2026 - 06:44:10 EST


btrfs currently provides its own 64-bit safe version of
is_power_of_2(), in order to handle 64-bit values on 32-bit systems.

Since other subsystems also have similar helpers, a new implementation
has been added to linux/log2.h. Use this instead of the btrfs-specific
one.

Signed-off-by: David Gow <david@xxxxxxxxxxxx>
---

This basically just replaces a btrfs helper with the version in patch 1.
It probably doesn't make sense for this series to go in via the btrfs
tree, so it's probably worth either accepting the posssibility for a
conflict, or sending this patch in separately after the first one lands.

Cheers,
-- David

[This patch was introduced in v2 of the series.]

---
fs/btrfs/misc.h | 7 +------
fs/btrfs/zoned.c | 2 +-
2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/misc.h b/fs/btrfs/misc.h
index 802060943180..e8be78341dc0 100644
--- a/fs/btrfs/misc.h
+++ b/fs/btrfs/misc.h
@@ -110,15 +110,10 @@ static inline u64 mult_perc(u64 num, u32 percent)
{
return div_u64(num * percent, 100);
}
-/* Copy of is_power_of_two that is 64bit safe */
-static inline bool is_power_of_two_u64(u64 n)
-{
- return n != 0 && (n & (n - 1)) == 0;
-}

static inline bool has_single_bit_set(u64 n)
{
- return is_power_of_two_u64(n);
+ return is_power_of_2_u64(n);
}

/*
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index a016cb471beb..b90ac4ff71b8 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -421,7 +421,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache)
zone_sectors = bdev_zone_sectors(bdev);
}

- ASSERT(is_power_of_two_u64(zone_sectors));
+ ASSERT(is_power_of_2_u64(zone_sectors));
zone_info->zone_size = zone_sectors << SECTOR_SHIFT;

/* We reject devices with a zone size larger than 8GB */
--
2.55.0