[PATCH v2 06/12] tools/kernel.h: add BUILD_BUG_ON_NOT_POWER_OF_2 macro

From: Sasha Levin
Date: Sat Apr 18 2020 - 21:58:14 EST


This is now needed as a result of 12593b7467f9 ("locking/lockdep: Reduce
space occupied by stack traces").

Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
tools/include/linux/kernel.h | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h
index d2b3e1cc0218e..cc3d60623ca47 100644
--- a/tools/include/linux/kernel.h
+++ b/tools/include/linux/kernel.h
@@ -38,6 +38,12 @@
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))

+/* Force a compilation error if a constant expression is not a power of 2 */
+#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) \
+ BUILD_BUG_ON(((n) & ((n) - 1)) != 0)
+#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
+ BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
+
#ifndef max
#define max(x, y) ({ \
typeof(x) _max1 = (x); \
--
2.20.1