summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2016-01-24 23:27:48 +0900
committerTom Rini <trini@konsulko.com>2016-01-25 10:39:59 -0500
commit84b8bf6d5d2a52fb40124c881de162b094ff5cc1 (patch)
tree92f41f93188419298d31121a58a085d113190ef7
parentbe6b2b31708a4a87425a81811323191b67947e56 (diff)
downloadu-boot-84b8bf6d5d2a52fb40124c881de162b094ff5cc1.tar.gz
u-boot-84b8bf6d5d2a52fb40124c881de162b094ff5cc1.tar.xz
u-boot-84b8bf6d5d2a52fb40124c881de162b094ff5cc1.zip
bug.h: move BUILD_BUG_* defines to include/linux/bug.h
BUILD_BUG_* macros have been defined in several headers. It would be nice to collect them in include/linux/bug.h like Linux. This commit is cherry-picking useful macros from include/linux/bug.h of Linux 4.4. I did not import BUILD_BUG_ON_MSG() because it would not work if it is used with include/common.h in U-Boot. I'd like to postpone it until the root cause (the "error()" macro in include/common.h causes the name conflict with "__attribute__((error()))") is fixed. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Tom Rini <trini@konsulko.com>
-rw-r--r--arch/arm/mach-tegra/ap.c1
-rw-r--r--cmd/dtt.c1
-rw-r--r--drivers/gpio/gpio-uclass.c1
-rw-r--r--drivers/mtd/ubi/build.c1
-rw-r--r--drivers/net/fsl-mc/mc.c1
-rw-r--r--drivers/pinctrl/uniphier/pinctrl-uniphier.h4
-rw-r--r--drivers/usb/dwc3/gadget.c1
-rw-r--r--drivers/usb/dwc3/linux-compat.h2
-rw-r--r--fs/ubifs/replay.c1
-rw-r--r--fs/ubifs/super.c1
-rw-r--r--include/common.h3
-rw-r--r--include/linux/bug.h55
12 files changed, 64 insertions, 8 deletions
diff --git a/arch/arm/mach-tegra/ap.c b/arch/arm/mach-tegra/ap.c
index b4229f4575..a4fa00c9ad 100644
--- a/arch/arm/mach-tegra/ap.c
+++ b/arch/arm/mach-tegra/ap.c
@@ -8,6 +8,7 @@
/* Tegra AP (Application Processor) code */
#include <common.h>
+#include <linux/bug.h>
#include <asm/io.h>
#include <asm/arch/gp_padctrl.h>
#include <asm/arch/mc.h>
diff --git a/cmd/dtt.c b/cmd/dtt.c
index f2e750f2f1..dd427a3d0b 100644
--- a/cmd/dtt.c
+++ b/cmd/dtt.c
@@ -12,6 +12,7 @@
#include <dtt.h>
#include <i2c.h>
#include <tmu.h>
+#include <linux/bug.h>
#if defined CONFIG_DTT_SENSORS
static unsigned long sensor_initialized;
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 3ed4d8914c..d603b55902 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -10,6 +10,7 @@
#include <fdtdec.h>
#include <malloc.h>
#include <asm/gpio.h>
+#include <linux/bug.h>
#include <linux/ctype.h>
DECLARE_GLOBAL_DATA_PTR;
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index f484e62b32..baf4e2d25b 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -30,6 +30,7 @@
#include <linux/slab.h>
#include <linux/major.h>
#else
+#include <linux/bug.h>
#include <linux/log2.h>
#endif
#include <linux/err.h>
diff --git a/drivers/net/fsl-mc/mc.c b/drivers/net/fsl-mc/mc.c
index bac4610fd9..4b9b3720f7 100644
--- a/drivers/net/fsl-mc/mc.c
+++ b/drivers/net/fsl-mc/mc.c
@@ -5,6 +5,7 @@
*/
#include <common.h>
#include <errno.h>
+#include <linux/bug.h>
#include <asm/io.h>
#include <libfdt.h>
#include <fdt_support.h>
diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier.h b/drivers/pinctrl/uniphier/pinctrl-uniphier.h
index 7eaec6a702..6bdebf28cd 100644
--- a/drivers/pinctrl/uniphier/pinctrl-uniphier.h
+++ b/drivers/pinctrl/uniphier/pinctrl-uniphier.h
@@ -7,9 +7,7 @@
#ifndef __PINCTRL_UNIPHIER_H__
#define __PINCTRL_UNIPHIER_H__
-/* TODO: move this to include/linux/bug.h */
-#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
-
+#include <linux/bug.h>
#include <linux/kernel.h>
#include <linux/types.h>
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 8ff949d241..25ccc01d1b 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -18,6 +18,7 @@
#include <malloc.h>
#include <asm/dma-mapping.h>
#include <usb/lin_gadget_compat.h>
+#include <linux/bug.h>
#include <linux/list.h>
#include <linux/usb/ch9.h>
diff --git a/drivers/usb/dwc3/linux-compat.h b/drivers/usb/dwc3/linux-compat.h
index 6c9c2791a8..9e944a31be 100644
--- a/drivers/usb/dwc3/linux-compat.h
+++ b/drivers/usb/dwc3/linux-compat.h
@@ -17,8 +17,6 @@
#define dev_WARN(dev, format, arg...) debug(format, ##arg)
#define WARN_ON_ONCE(val) debug("Error %d\n", val)
-#define BUILD_BUG_ON_NOT_POWER_OF_2(n)
-
static inline size_t strlcat(char *dest, const char *src, size_t n)
{
strcat(dest, src);
diff --git a/fs/ubifs/replay.c b/fs/ubifs/replay.c
index d0fcd83058..176125e380 100644
--- a/fs/ubifs/replay.c
+++ b/fs/ubifs/replay.c
@@ -26,6 +26,7 @@
#include <linux/err.h>
#endif
#include "ubifs.h"
+#include <linux/bug.h>
#include <linux/list_sort.h>
/**
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index abe861a976..dcf3a47947 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -31,6 +31,7 @@
#include <common.h>
#include <malloc.h>
#include <memalign.h>
+#include <linux/bug.h>
#include <linux/log2.h>
#include <linux/stat.h>
#include <linux/err.h>
diff --git a/include/common.h b/include/common.h
index 7bed0cc0d1..1563d649f0 100644
--- a/include/common.h
+++ b/include/common.h
@@ -146,9 +146,6 @@ void __assert_fail(const char *assertion, const char *file, unsigned line,
#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
#endif /* BUG */
-/* Force a compilation error if condition is true */
-#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
-
typedef void (interrupt_handler_t)(void *);
#include <asm/u-boot.h> /* boot information for Linux kernel */
diff --git a/include/linux/bug.h b/include/linux/bug.h
new file mode 100644
index 0000000000..920e3796c3
--- /dev/null
+++ b/include/linux/bug.h
@@ -0,0 +1,55 @@
+#ifndef _LINUX_BUG_H
+#define _LINUX_BUG_H
+
+#include <linux/compiler.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_INVALID(e) (0)
+#define BUILD_BUG_ON(condition) (0)
+#define BUILD_BUG() (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); }))
+
+/*
+ * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the
+ * expression but avoids the generation of any code, even if that expression
+ * has side-effects.
+ */
+#define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e))))
+
+/**
+ * BUILD_BUG_ON - break compile if a condition is true.
+ * @condition: the condition which the compiler should know is false.
+ *
+ * If you have some code which relies on certain constants being equal, or
+ * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to
+ * detect if someone changes it.
+ *
+ * The implementation uses gcc's reluctance to create a negative array, but gcc
+ * (as of 4.4) only emits that error for obvious cases (e.g. not arguments to
+ * inline functions). Luckily, in 4.3 they added the "error" function
+ * attribute just for this type of case. Thus, we use a negative sized array
+ * (should always create an error on gcc versions older than 4.4) and then call
+ * an undefined function with the error attribute (should always create an
+ * error on gcc 4.3 and later). If for some reason, neither creates a
+ * compile-time error, we'll still have a link-time error, which is harder to
+ * track down.
+ */
+#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
+
+#endif /* __CHECKER__ */
+
+#endif /* _LINUX_BUG_H */