[Intel-gfx] [PATCH 1/4] log2: add helper __IS_POWER_OF_2()

Jani Nikula jani.nikula at intel.com
Thu Mar 30 10:42:40 UTC 2023


Add a helper to avoid duplication in the subsequent changes.

Cc: Andrew Morton <akpm at linux-foundation.org>
Cc: Christian König <christian.koenig at amd.com>
Cc: David Gow <davidgow at google.com>
Signed-off-by: Jani Nikula <jani.nikula at intel.com>
---
 include/linux/log2.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/log2.h b/include/linux/log2.h
index 9f30d087a128..19e773116ae3 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -33,6 +33,8 @@ int __ilog2_u64(u64 n)
 }
 #endif
 
+#define __IS_POWER_OF_2(n) ((n) != 0 && (((n) & ((n) - 1)) == 0))
+
 /**
  * is_power_of_2() - check if a value is a power of two
  * @n: the value to check
@@ -44,7 +46,7 @@ int __ilog2_u64(u64 n)
 static inline __attribute__((const))
 bool is_power_of_2(unsigned long n)
 {
-	return (n != 0 && ((n & (n - 1)) == 0));
+	return __IS_POWER_OF_2(n);
 }
 
 /**
-- 
2.39.2



More information about the Intel-gfx mailing list