From 79c8264e443471eb2748c93680acce54d14d2225 Mon Sep 17 00:00:00 2001
From: David Sterba <dsterba@suse.com>
Date: Tue, 1 Oct 2019 19:40:15 +0200
Subject: [PATCH] btrfs: add 64bit safe helper for power of two checks

As is_power_of_two takes unsigned long, it's not safe on 32bit
architectures, but we could pass any u64 value in seveal places. Add a
separate helper and also an alias that better expresses the purpose for
which the helper is used.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/misc.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/fs/btrfs/misc.h b/fs/btrfs/misc.h
index 7d564924dfeb9..72bab64ecf60a 100644
--- a/fs/btrfs/misc.h
+++ b/fs/btrfs/misc.h
@@ -47,4 +47,15 @@ static inline u64 div_factor_fine(u64 num, int factor)
 	return div_u64(num, 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);
+}
+
 #endif
-- 
2.30.2