* [PATCH 1/3] linux/bug.h: move BUILD_BUG_ON*() macros
2015-01-29 2:14 [PATCH 0/3] Slim down include/common.h more Masahiro Yamada
@ 2015-01-29 2:14 ` Masahiro Yamada
2015-01-29 2:14 ` [PATCH 2/3] asm-generic/bug.h: move BUG(), BUG_ON(), WARN(), WARN_ON() macros Masahiro Yamada
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Masahiro Yamada @ 2015-01-29 2:14 UTC (permalink / raw)
To: barebox
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/3] asm-generic/bug.h: move BUG(), BUG_ON(), WARN(), WARN_ON() macros
2015-01-29 2:14 [PATCH 0/3] Slim down include/common.h more Masahiro Yamada
2015-01-29 2:14 ` [PATCH 1/3] linux/bug.h: move BUILD_BUG_ON*() macros Masahiro Yamada
@ 2015-01-29 2:14 ` 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
3 siblings, 0 replies; 6+ messages in thread
From: Masahiro Yamada @ 2015-01-29 2:14 UTC (permalink / raw)
To: barebox
In Linux, these macros are defined in include/asm-generic/bug.h.
To tidy up common.h, move BUG(), BUG_ON(), WARN(), WARN_ON() there.
Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
---
include/asm-generic/bug.h | 37 +++++++++++++++++++++++++++++++++++++
include/common.h | 32 --------------------------------
include/linux/bug.h | 2 ++
3 files changed, 39 insertions(+), 32 deletions(-)
create mode 100644 include/asm-generic/bug.h
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
new file mode 100644
index 0000000..8583d24
--- /dev/null
+++ b/include/asm-generic/bug.h
@@ -0,0 +1,37 @@
+#ifndef _ASM_GENERIC_BUG_H
+#define _ASM_GENERIC_BUG_H
+
+#include <linux/compiler.h>
+
+#define BUG() do { \
+ printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
+ panic("BUG!"); \
+} while (0)
+#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
+
+
+#define __WARN() do { \
+ printf("WARNING: at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
+} while (0)
+
+#ifndef WARN_ON
+#define WARN_ON(condition) ({ \
+ int __ret_warn_on = !!(condition); \
+ if (unlikely(__ret_warn_on)) \
+ __WARN(); \
+ unlikely(__ret_warn_on); \
+})
+#endif
+
+#ifndef WARN
+#define WARN(condition, format...) ({ \
+ int __ret_warn_on = !!(condition); \
+ if (unlikely(__ret_warn_on)) { \
+ __WARN(); \
+ puts("WARNING: "); \
+ printf(format); \
+ } \
+ unlikely(__ret_warn_on); \
+})
+#endif
+#endif
diff --git a/include/common.h b/include/common.h
index c30f6bd..289f7c9 100644
--- a/include/common.h
+++ b/include/common.h
@@ -50,38 +50,6 @@
#error "None of __LITTLE_ENDIAN and __BIG_ENDIAN are defined"
#endif
-#define BUG() do { \
- printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
- panic("BUG!"); \
-} while (0)
-#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
-
-
-#define __WARN() do { \
- printf("WARNING: at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
-} while (0)
-
-#ifndef WARN_ON
-#define WARN_ON(condition) ({ \
- int __ret_warn_on = !!(condition); \
- if (unlikely(__ret_warn_on)) \
- __WARN(); \
- unlikely(__ret_warn_on); \
-})
-#endif
-
-#ifndef WARN
-#define WARN(condition, format...) ({ \
- int __ret_warn_on = !!(condition); \
- if (unlikely(__ret_warn_on)) { \
- __WARN(); \
- puts("WARNING: "); \
- printf(format); \
- } \
- unlikely(__ret_warn_on); \
-})
-#endif
-
#include <asm/barebox.h> /* boot information for Linux kernel */
/*
diff --git a/include/linux/bug.h b/include/linux/bug.h
index 3449837..7295618 100644
--- a/include/linux/bug.h
+++ b/include/linux/bug.h
@@ -1,6 +1,8 @@
#ifndef _LINUX_BUG_H
#define _LINUX_BUG_H
+#include <asm-generic/bug.h>
+
#ifdef __CHECKER__
#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)
#define BUILD_BUG_ON_ZERO(e) (0)
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] linux/kernel.h: move some macros and prototypes
2015-01-29 2:14 [PATCH 0/3] Slim down include/common.h more Masahiro Yamada
2015-01-29 2:14 ` [PATCH 1/3] linux/bug.h: move BUILD_BUG_ON*() macros Masahiro Yamada
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 ` Masahiro Yamada
2015-01-29 3:54 ` [PATCH 0/3] Slim down include/common.h more Masahiro Yamada
3 siblings, 0 replies; 6+ messages in thread
From: Masahiro Yamada @ 2015-01-29 2:14 UTC (permalink / raw)
To: barebox
The include/common.h is still cluttered (although much better than
U-Boot). It contains various utility macros that originates
in Linux. Move them to the original place, include/linux/kernel.h,
to slim down include/common.h.
Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
---
include/common.h | 58 -----------------------------------------------
include/linux/kernel.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 58 deletions(-)
diff --git a/include/common.h b/include/common.h
index 289f7c9..eef371c 100644
--- a/include/common.h
+++ b/include/common.h
@@ -27,7 +27,6 @@
#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>
@@ -58,7 +57,6 @@
void reginfo(void);
void __noreturn hang (void);
-void __noreturn panic(const char *fmt, ...);
char *size_human_readable(unsigned long long size);
@@ -76,11 +74,6 @@ void __noreturn poweroff(void);
void udelay (unsigned long);
void mdelay (unsigned long);
-/* lib_generic/vsprintf.c */
-ulong simple_strtoul(const char *cp,char **endp,unsigned int base);
-unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base);
-long simple_strtol(const char *cp,char **endp,unsigned int base);
-
/* lib_generic/crc32.c */
uint32_t crc32(uint32_t, const void*, unsigned int);
uint32_t crc32_no_comp(uint32_t, const void*, unsigned int);
@@ -144,13 +137,8 @@ static inline char *shell_expand(char *str)
}
#endif
-#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))
-#define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a)))
-#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
#define ARRAY_AND_SIZE(x) (x), ARRAY_SIZE(x)
/*
@@ -164,17 +152,6 @@ static inline char *shell_expand(char *str)
char __##name[sizeof(type) * (size) + (align) - 1]; \
type *name = (type *)ALIGN((uintptr_t)__##name, align)
-/**
- * container_of - cast a member of a structure out to the containing structure
- * @ptr: the pointer to the member.
- * @type: the type of the container struct this is embedded in.
- * @member: the name of the member within the struct.
- *
- */
-#define container_of(ptr, type, member) ({ \
- const typeof( ((type *)0)->member ) *__mptr = (ptr); \
- (type *)( (char *)__mptr - offsetof(type,member) );})
-
#define PAGE_SIZE 4096
#define PAGE_SHIFT 12
#define PAGE_ALIGN(s) (((s) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
@@ -216,41 +193,6 @@ void barebox_set_hostname(const char *);
#define IOMEM(addr) ((void __force __iomem *)(addr))
#endif
-#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
-
-#define DIV_ROUND_CLOSEST(x, divisor)( \
-{ \
- typeof(divisor) __divisor = divisor; \
- (((x) + ((__divisor) / 2)) / (__divisor)); \
-} \
-)
-
-/**
- * upper_32_bits - return bits 32-63 of a number
- * @n: the number we're accessing
- *
- * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress
- * the "right shift count >= width of type" warning when that quantity is
- * 32-bits.
- */
-#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
-
-/**
- * lower_32_bits - return bits 0-31 of a number
- * @n: the number we're accessing
- */
-#define lower_32_bits(n) ((u32)(n))
-
-#define abs(x) ({ \
- long __x = (x); \
- (__x < 0) ? -__x : __x; \
- })
-
-#define abs64(x) ({ \
- s64 __x = (x); \
- (__x < 0) ? -__x : __x; \
- })
-
/*
* Check if two regions overlap. returns true if they do, false otherwise
*/
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index a039590..3f2644c 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -2,6 +2,7 @@
#define _LINUX_KERNEL_H
#include <linux/compiler.h>
+#include <linux/bug.h>
#include <linux/barebox-wrapper.h>
#define USHRT_MAX ((u16)(~0U))
@@ -31,6 +32,13 @@
#define S64_MAX ((s64)(U64_MAX>>1))
#define S64_MIN ((s64)(-S64_MAX - 1))
+#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1)
+#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
+#define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a)))
+#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
+
/*
* This looks more complex than it should be. But we need to
* get the type for the ~ right in round_down (it needs to be
@@ -44,6 +52,47 @@
#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
#define round_down(x, y) ((x) & ~__round_mask(x, y))
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+
+#define DIV_ROUND_CLOSEST(x, divisor)( \
+{ \
+ typeof(divisor) __divisor = divisor; \
+ (((x) + ((__divisor) / 2)) / (__divisor)); \
+} \
+)
+
+/**
+ * upper_32_bits - return bits 32-63 of a number
+ * @n: the number we're accessing
+ *
+ * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress
+ * the "right shift count >= width of type" warning when that quantity is
+ * 32-bits.
+ */
+#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
+
+/**
+ * lower_32_bits - return bits 0-31 of a number
+ * @n: the number we're accessing
+ */
+#define lower_32_bits(n) ((u32)(n))
+
+#define abs(x) ({ \
+ long __x = (x); \
+ (__x < 0) ? -__x : __x; \
+ })
+
+#define abs64(x) ({ \
+ s64 __x = (x); \
+ (__x < 0) ? -__x : __x; \
+ })
+
+void __noreturn panic(const char *fmt, ...);
+
+extern unsigned long simple_strtoul(const char *,char **,unsigned int);
+extern long simple_strtol(const char *,char **,unsigned int);
+extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
+
/*
* min()/max()/clamp() macros that also do
* strict type-checking.. See the
@@ -197,4 +246,16 @@ static inline char *hex_byte_pack_upper(char *buf, u8 byte)
return buf;
}
+/**
+ * container_of - cast a member of a structure out to the containing structure
+ * @ptr: the pointer to the member.
+ * @type: the type of the container struct this is embedded in.
+ * @member: the name of the member within the struct.
+ *
+ */
+#define container_of(ptr, type, member) ({ \
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) );})
+
+
#endif /* _LINUX_KERNEL_H */
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread