aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kernel.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r--include/linux/kernel.h21
1 files changed, 18 insertions, 3 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 3fc9f5aab5f8..9365227dbaf6 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -44,6 +44,16 @@ extern const char linux_proc_banner[];
44 44
45#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) 45#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
46 46
47/*
48 * This looks more complex than it should be. But we need to
49 * get the type for the ~ right in round_down (it needs to be
50 * as wide as the result!), and we want to evaluate the macro
51 * arguments just once each.
52 */
53#define __round_mask(x, y) ((__typeof__(x))((y)-1))
54#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
55#define round_down(x, y) ((x) & ~__round_mask(x, y))
56
47#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) 57#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
48#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) 58#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
49#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) 59#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
@@ -124,7 +134,7 @@ extern int _cond_resched(void);
124#endif 134#endif
125 135
126#ifdef CONFIG_DEBUG_SPINLOCK_SLEEP 136#ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
127 void __might_sleep(char *file, int line, int preempt_offset); 137 void __might_sleep(const char *file, int line, int preempt_offset);
128/** 138/**
129 * might_sleep - annotation for functions that can sleep 139 * might_sleep - annotation for functions that can sleep
130 * 140 *
@@ -138,7 +148,8 @@ extern int _cond_resched(void);
138# define might_sleep() \ 148# define might_sleep() \
139 do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) 149 do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
140#else 150#else
141 static inline void __might_sleep(char *file, int line, int preempt_offset) { } 151 static inline void __might_sleep(const char *file, int line,
152 int preempt_offset) { }
142# define might_sleep() do { might_resched(); } while (0) 153# define might_sleep() do { might_resched(); } while (0)
143#endif 154#endif
144 155
@@ -415,7 +426,7 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
415 .burst = DEFAULT_RATELIMIT_BURST, \ 426 .burst = DEFAULT_RATELIMIT_BURST, \
416 }; \ 427 }; \
417 \ 428 \
418 if (!__ratelimit(&_rs)) \ 429 if (__ratelimit(&_rs)) \
419 printk(fmt, ##__VA_ARGS__); \ 430 printk(fmt, ##__VA_ARGS__); \
420}) 431})
421#else 432#else
@@ -734,6 +745,10 @@ struct sysinfo {
734/* Force a compilation error if condition is constant and true */ 745/* Force a compilation error if condition is constant and true */
735#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) 746#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
736 747
748/* Force a compilation error if a constant expression is not a power of 2 */
749#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
750 BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
751
737/* Force a compilation error if condition is true, but also produce a 752/* Force a compilation error if condition is true, but also produce a
738 result (of value 0 and type size_t), so the expression can be used 753 result (of value 0 and type size_t), so the expression can be used
739 e.g. in a structure initializer (or where-ever else comma expressions 754 e.g. in a structure initializer (or where-ever else comma expressions