mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-30 19:11:37 +00:00
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>
This commit is contained in:
parent
be6b2b3170
commit
84b8bf6d5d
12 changed files with 64 additions and 8 deletions
|
@ -8,6 +8,7 @@
|
||||||
/* Tegra AP (Application Processor) code */
|
/* Tegra AP (Application Processor) code */
|
||||||
|
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
|
#include <linux/bug.h>
|
||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
#include <asm/arch/gp_padctrl.h>
|
#include <asm/arch/gp_padctrl.h>
|
||||||
#include <asm/arch/mc.h>
|
#include <asm/arch/mc.h>
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <dtt.h>
|
#include <dtt.h>
|
||||||
#include <i2c.h>
|
#include <i2c.h>
|
||||||
#include <tmu.h>
|
#include <tmu.h>
|
||||||
|
#include <linux/bug.h>
|
||||||
|
|
||||||
#if defined CONFIG_DTT_SENSORS
|
#if defined CONFIG_DTT_SENSORS
|
||||||
static unsigned long sensor_initialized;
|
static unsigned long sensor_initialized;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <fdtdec.h>
|
#include <fdtdec.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <asm/gpio.h>
|
#include <asm/gpio.h>
|
||||||
|
#include <linux/bug.h>
|
||||||
#include <linux/ctype.h>
|
#include <linux/ctype.h>
|
||||||
|
|
||||||
DECLARE_GLOBAL_DATA_PTR;
|
DECLARE_GLOBAL_DATA_PTR;
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/major.h>
|
#include <linux/major.h>
|
||||||
#else
|
#else
|
||||||
|
#include <linux/bug.h>
|
||||||
#include <linux/log2.h>
|
#include <linux/log2.h>
|
||||||
#endif
|
#endif
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <linux/bug.h>
|
||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
#include <libfdt.h>
|
#include <libfdt.h>
|
||||||
#include <fdt_support.h>
|
#include <fdt_support.h>
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
#ifndef __PINCTRL_UNIPHIER_H__
|
#ifndef __PINCTRL_UNIPHIER_H__
|
||||||
#define __PINCTRL_UNIPHIER_H__
|
#define __PINCTRL_UNIPHIER_H__
|
||||||
|
|
||||||
/* TODO: move this to include/linux/bug.h */
|
#include <linux/bug.h>
|
||||||
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
|
|
||||||
|
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <asm/dma-mapping.h>
|
#include <asm/dma-mapping.h>
|
||||||
#include <usb/lin_gadget_compat.h>
|
#include <usb/lin_gadget_compat.h>
|
||||||
|
#include <linux/bug.h>
|
||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
|
|
||||||
#include <linux/usb/ch9.h>
|
#include <linux/usb/ch9.h>
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
#define dev_WARN(dev, format, arg...) debug(format, ##arg)
|
#define dev_WARN(dev, format, arg...) debug(format, ##arg)
|
||||||
#define WARN_ON_ONCE(val) debug("Error %d\n", val)
|
#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)
|
static inline size_t strlcat(char *dest, const char *src, size_t n)
|
||||||
{
|
{
|
||||||
strcat(dest, src);
|
strcat(dest, src);
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#endif
|
#endif
|
||||||
#include "ubifs.h"
|
#include "ubifs.h"
|
||||||
|
#include <linux/bug.h>
|
||||||
#include <linux/list_sort.h>
|
#include <linux/list_sort.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <memalign.h>
|
#include <memalign.h>
|
||||||
|
#include <linux/bug.h>
|
||||||
#include <linux/log2.h>
|
#include <linux/log2.h>
|
||||||
#include <linux/stat.h>
|
#include <linux/stat.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.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)
|
#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
|
||||||
#endif /* BUG */
|
#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 *);
|
typedef void (interrupt_handler_t)(void *);
|
||||||
|
|
||||||
#include <asm/u-boot.h> /* boot information for Linux kernel */
|
#include <asm/u-boot.h> /* boot information for Linux kernel */
|
||||||
|
|
55
include/linux/bug.h
Normal file
55
include/linux/bug.h
Normal file
|
@ -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 */
|
Loading…
Add table
Reference in a new issue