From: Masahiro Yamada <yamada.m@jp.panasonic.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/3] linux/bug.h: move BUILD_BUG_ON*() macros
Date: Thu, 29 Jan 2015 11:14:05 +0900 [thread overview]
Message-ID: <1422497647-28863-2-git-send-email-yamada.m@jp.panasonic.com> (raw)
In-Reply-To: <1422497647-28863-1-git-send-email-yamada.m@jp.panasonic.com>
In Linux, the macros BUILD_BUG_ON* are defined in include/linux/bug.h.
To tidy up common.h, move BUILD_BUG_* there.
MAYBE_BUILD_BUG_ON is not used in barebox and it was removed from Linux
long time ago. Drop it from barebox, too.
Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
---
include/common.h | 20 +-------------------
include/linux/bug.h | 28 ++++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 19 deletions(-)
create mode 100644 include/linux/bug.h
diff --git a/include/common.h b/include/common.h
index f3f5c0f..c30f6bd 100644
--- a/include/common.h
+++ b/include/common.h
@@ -27,6 +27,7 @@
#include <linux/types.h>
#include <linux/string.h>
#include <linux/kernel.h>
+#include <linux/bug.h>
#include <linux/stddef.h>
#include <asm/common.h>
#include <printk.h>
@@ -175,25 +176,6 @@ static inline char *shell_expand(char *str)
}
#endif
-/* Force a compilation error if condition is true */
-#define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition))
-
-/* Force a compilation error if condition is constant and true */
-#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
-
-/* 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))
-
-/*
- * 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
- * e.g. in a structure initializer (or where-ever else comma
- * expressions aren't permitted).
- */
-#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
-#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
-
#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1)
#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
#define ALIGN_DOWN(x, a) ((x) & ~((typeof(x))(a) - 1))
diff --git a/include/linux/bug.h b/include/linux/bug.h
new file mode 100644
index 0000000..3449837
--- /dev/null
+++ b/include/linux/bug.h
@@ -0,0 +1,28 @@
+#ifndef _LINUX_BUG_H
+#define _LINUX_BUG_H
+
+#ifdef __CHECKER__
+#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)
+#define BUILD_BUG_ON_ZERO(e) (0)
+#define BUILD_BUG_ON_NULL(e) ((void*)0)
+#define BUILD_BUG_ON(condition) (0)
+#else /* __CHECKER__ */
+
+/* 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))
+
+/* 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
+ e.g. in a structure initializer (or where-ever else comma expressions
+ aren't permitted). */
+#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
+#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
+
+/* Force a compilation error if condition is true */
+#define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition))
+
+#endif
+
+
+#endif /* _LINUX_BUG_H */
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-01-29 2:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-29 2:14 [PATCH 0/3] Slim down include/common.h more Masahiro Yamada
2015-01-29 2:14 ` Masahiro Yamada [this message]
2015-01-29 2:14 ` [PATCH 2/3] asm-generic/bug.h: move BUG(), BUG_ON(), WARN(), WARN_ON() macros Masahiro Yamada
2015-01-29 2:14 ` [PATCH 3/3] linux/kernel.h: move some macros and prototypes Masahiro Yamada
2015-01-29 3:54 ` [PATCH 0/3] Slim down include/common.h more Masahiro Yamada
2015-01-29 8:04 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1422497647-28863-2-git-send-email-yamada.m@jp.panasonic.com \
--to=yamada.m@jp.panasonic.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox