Re: [PATCH] debug: fix BUILD_BUG_ON() for non-constant expressions

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Boaz Harrosh
Date: Monday, August 18, 2008 - 5:32 am

Boaz Harrosh wrote:

with this patch:
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index aaa998f..91d98f2 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -468,7 +468,12 @@ struct sysinfo {
 };
 
 /* Force a compilation error if condition is true */
-#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
+// #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
+#define BUILD_BUG_ON(condition)					\
+do { 								\
+	enum { bad = !!(condition)}; 				\
+	static struct { char arr[1 - 2*bad]; } x __maybe_unused;\
+} while(0)
 
 /* Force a compilation error if condition is true, but also produce a
    result (of value 0 and type size_t), so the expression can be used


I found another BUILD_BUG_ON() none const bug, here:

diff --git a/drivers/net/niu.c b/drivers/net/niu.c
index e4765b7..1469a38 100644
--- a/drivers/net/niu.c
+++ b/drivers/net/niu.c
@@ -5133,9 +5133,9 @@ static void niu_init_tx_bmac(struct niu *np, u64 min, u64 max)
 
 static void niu_init_tx_mac(struct niu *np)
 {
-	u64 min, max;
+	u64 max;
 
-	min = 64;
+	enum { min = 64 } ;
 	if (np->dev->mtu > ETH_DATA_LEN)
 		max = 9216;
 	else

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] BUILD_BUG_ON sucks, Alexey Dobriyan, (Sat Aug 16, 3:09 am)
Re: [PATCH] BUILD_BUG_ON sucks, Rusty Russell, (Sat Aug 16, 3:55 am)
Re: [PATCH] BUILD_BUG_ON sucks, Andrew Morton, (Sat Aug 16, 10:46 am)
Re: [PATCH] BUILD_BUG_ON sucks, Linus Torvalds, (Sat Aug 16, 1:07 pm)
Re: [PATCH] BUILD_BUG_ON sucks, Theodore Tso, (Sun Aug 17, 5:19 am)
Re: [PATCH] BUILD_BUG_ON sucks, Andrew Morton, (Sun Aug 17, 9:33 am)
Re: [PATCH] debug: fix BUILD_BUG_ON() for non-constant exp ..., Boaz Harrosh, (Mon Aug 18, 5:32 am)