mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Gow <david@davidgow.net>
To: Jim Cromie <jim.cromie@gmail.com>,
	"Maciej W . Rozycki" <macro@orcam.me.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Matthew Auld <matthew.auld@intel.com>,
	Arun Pravin <arunpravin.paneerselvam@amd.com>,
	Joel Fernandes <joelagnelf@nvidia.com>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Chris Mason <mason@kernel.org>, David Sterba <dsterba@suse.com>
Cc: David Gow <david@davidgow.net>,
	dri-devel@lists.freedesktop.org, linux-btrfs@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/3] fs:btrfs: Use the new global is_power_of_2_u64() helper
Date: Sun, 30 Aug 2026 18:33:17 +0800	[thread overview]
Message-ID: <20260830103321.2042968-3-david@davidgow.net> (raw)
In-Reply-To: <20260830103321.2042968-1-david@davidgow.net>

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@davidgow.net>
---

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


  parent reply	other threads:[~2026-08-30 10:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-30 10:33 [PATCH v2 1/3] linux/log2.h: Add 64-bit safe variants of power-of-two functions David Gow
2026-08-30 10:33 ` [PATCH v2 2/3] drm_buddy: fix power-of-2 rounding errs David Gow
2026-08-30 10:33 ` David Gow [this message]
2026-08-30 11:43 ` [PATCH v2 1/3] linux/log2.h: Add 64-bit safe variants of power-of-two functions David Laight

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=20260830103321.2042968-3-david@davidgow.net \
    --to=david@davidgow.net \
    --cc=airlied@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=arunpravin.paneerselvam@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=dsterba@suse.com \
    --cc=jim.cromie@gmail.com \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=macro@orcam.me.uk \
    --cc=mason@kernel.org \
    --cc=matthew.auld@intel.com \
    --cc=simona@ffwll.ch \
    /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

all inboxes | Powered by JetHome®