[ovs-dev] [PATCH v3] datapath: Fix sparse warning for symbol 'BUILD_BUG_ON_NOT_POWER_OF_2'

Pravin B Shelar pshelar at nicira.com
Tue Oct 30 21:15:08 UTC 2012


v2-v3:
	- Added bug.h to Modules.mk
v1-v2:
	- Moved BUILD_BUG_ON_NOT_POWER_OF_2 symbol definition for bug.h
--8<--------------------------cut here-------------------------->8--

BUILD_BUG_ON_NOT_POWER_OF_2 symbol is moved from kernel.h to
bug.h in 3.4.  Therefore sparse is giving warning:

include/linux/bug.h:15:9: warning: preprocessor token
BUILD_BUG_ON_NOT_POWER_OF_2 redefined
ovs/datapath/linux/compat/include/linux/kernel.h:44:9:
this was the original definition

Signed-off-by: Pravin B Shelar <pshelar at nicira.com>
---
 datapath/linux/Modules.mk                    |    1 +
 datapath/linux/compat/include/linux/bug.h    |   12 ++++++++++++
 datapath/linux/compat/include/linux/kernel.h |   10 ++++------
 3 files changed, 17 insertions(+), 6 deletions(-)
 create mode 100644 datapath/linux/compat/include/linux/bug.h

diff --git a/datapath/linux/Modules.mk b/datapath/linux/Modules.mk
index 8ce6115..14d23a4 100644
--- a/datapath/linux/Modules.mk
+++ b/datapath/linux/Modules.mk
@@ -13,6 +13,7 @@ openvswitch_sources += \
 	linux/compat/time.c	\
 	linux/compat/workqueue.c
 openvswitch_headers += \
+	linux/compat/include/linux/bug.h \
 	linux/compat/include/linux/compiler.h \
 	linux/compat/include/linux/compiler-gcc.h \
 	linux/compat/include/linux/cpumask.h \
diff --git a/datapath/linux/compat/include/linux/bug.h b/datapath/linux/compat/include/linux/bug.h
new file mode 100644
index 0000000..d24e68e
--- /dev/null
+++ b/datapath/linux/compat/include/linux/bug.h
@@ -0,0 +1,12 @@
+#ifndef __BUG_H_WRAPPER
+#define __BUG_H_WRAPPER 1
+
+#include_next <linux/bug.h>
+
+#ifndef BUILD_BUG_ON_NOT_POWER_OF_2
+/* 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) == 0 || (((n) & ((n) - 1)) != 0))
+#endif
+
+#endif
diff --git a/datapath/linux/compat/include/linux/kernel.h b/datapath/linux/compat/include/linux/kernel.h
index 812f213..069839b 100644
--- a/datapath/linux/compat/include/linux/kernel.h
+++ b/datapath/linux/compat/include/linux/kernel.h
@@ -7,7 +7,11 @@
 #endif
 
 #include <linux/version.h>
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)
+/* BUILD_BUG_ON_NOT_POWER_OF_2 definition */
 #include <linux/bug.h>
+#endif
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
 #undef pr_emerg
 #define pr_emerg(fmt, ...) \
@@ -39,12 +43,6 @@
 #define pr_warn pr_warning
 #endif
 
-#ifndef BUILD_BUG_ON_NOT_POWER_OF_2
-/* 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) == 0 || (((n) & ((n) - 1)) != 0))
-#endif
-
 #if defined(CONFIG_PREEMPT) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
 #error "CONFIG_PREEMPT is broken before 2.6.21--see commit 4498121ca3, \"[NET]: Handle disabled preemption in gfp_any()\""
 #endif
-- 
1.7.10




More information about the dev mailing list