diff options
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r-- | include/linux/kernel.h | 102 |
1 files changed, 81 insertions, 21 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 2df44e773270..4d46e299afb5 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -20,6 +20,9 @@ | |||
20 | extern const char linux_banner[]; | 20 | extern const char linux_banner[]; |
21 | extern const char linux_proc_banner[]; | 21 | extern const char linux_proc_banner[]; |
22 | 22 | ||
23 | #define USHORT_MAX ((u16)(~0U)) | ||
24 | #define SHORT_MAX ((s16)(USHORT_MAX>>1)) | ||
25 | #define SHORT_MIN (-SHORT_MAX - 1) | ||
23 | #define INT_MAX ((int)(~0U>>1)) | 26 | #define INT_MAX ((int)(~0U>>1)) |
24 | #define INT_MIN (-INT_MAX - 1) | 27 | #define INT_MIN (-INT_MAX - 1) |
25 | #define UINT_MAX (~0U) | 28 | #define UINT_MAX (~0U) |
@@ -188,6 +191,7 @@ extern int log_buf_copy(char *dest, int idx, int len); | |||
188 | extern int printk_ratelimit_jiffies; | 191 | extern int printk_ratelimit_jiffies; |
189 | extern int printk_ratelimit_burst; | 192 | extern int printk_ratelimit_burst; |
190 | extern int printk_ratelimit(void); | 193 | extern int printk_ratelimit(void); |
194 | extern int __ratelimit(int ratelimit_jiffies, int ratelimit_burst); | ||
191 | extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst); | 195 | extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst); |
192 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, | 196 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, |
193 | unsigned int interval_msec); | 197 | unsigned int interval_msec); |
@@ -255,6 +259,7 @@ extern enum system_states { | |||
255 | #define TAINT_USER (1<<6) | 259 | #define TAINT_USER (1<<6) |
256 | #define TAINT_DIE (1<<7) | 260 | #define TAINT_DIE (1<<7) |
257 | #define TAINT_OVERRIDDEN_ACPI_TABLE (1<<8) | 261 | #define TAINT_OVERRIDDEN_ACPI_TABLE (1<<8) |
262 | #define TAINT_WARN (1<<9) | ||
258 | 263 | ||
259 | extern void dump_stack(void) __cold; | 264 | extern void dump_stack(void) __cold; |
260 | 265 | ||
@@ -293,10 +298,8 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, | |||
293 | #define pr_debug(fmt, arg...) \ | 298 | #define pr_debug(fmt, arg...) \ |
294 | printk(KERN_DEBUG fmt, ##arg) | 299 | printk(KERN_DEBUG fmt, ##arg) |
295 | #else | 300 | #else |
296 | static inline int __attribute__ ((format (printf, 1, 2))) pr_debug(const char * fmt, ...) | 301 | #define pr_debug(fmt, arg...) \ |
297 | { | 302 | ({ if (0) printk(KERN_DEBUG fmt, ##arg); 0; }) |
298 | return 0; | ||
299 | } | ||
300 | #endif | 303 | #endif |
301 | 304 | ||
302 | /* | 305 | /* |
@@ -335,33 +338,90 @@ static inline int __attribute__ ((format (printf, 1, 2))) pr_debug(const char * | |||
335 | #endif /* __LITTLE_ENDIAN */ | 338 | #endif /* __LITTLE_ENDIAN */ |
336 | 339 | ||
337 | /* | 340 | /* |
338 | * min()/max() macros that also do | 341 | * min()/max()/clamp() macros that also do |
339 | * strict type-checking.. See the | 342 | * strict type-checking.. See the |
340 | * "unnecessary" pointer comparison. | 343 | * "unnecessary" pointer comparison. |
341 | */ | 344 | */ |
342 | #define min(x,y) ({ \ | 345 | #define min(x, y) ({ \ |
343 | typeof(x) _x = (x); \ | 346 | typeof(x) _min1 = (x); \ |
344 | typeof(y) _y = (y); \ | 347 | typeof(y) _min2 = (y); \ |
345 | (void) (&_x == &_y); \ | 348 | (void) (&_min1 == &_min2); \ |
346 | _x < _y ? _x : _y; }) | 349 | _min1 < _min2 ? _min1 : _min2; }) |
347 | 350 | ||
348 | #define max(x,y) ({ \ | 351 | #define max(x, y) ({ \ |
349 | typeof(x) _x = (x); \ | 352 | typeof(x) _max1 = (x); \ |
350 | typeof(y) _y = (y); \ | 353 | typeof(y) _max2 = (y); \ |
351 | (void) (&_x == &_y); \ | 354 | (void) (&_max1 == &_max2); \ |
352 | _x > _y ? _x : _y; }) | 355 | _max1 > _max2 ? _max1 : _max2; }) |
356 | |||
357 | /** | ||
358 | * clamp - return a value clamped to a given range with strict typechecking | ||
359 | * @val: current value | ||
360 | * @min: minimum allowable value | ||
361 | * @max: maximum allowable value | ||
362 | * | ||
363 | * This macro does strict typechecking of min/max to make sure they are of the | ||
364 | * same type as val. See the unnecessary pointer comparisons. | ||
365 | */ | ||
366 | #define clamp(val, min, max) ({ \ | ||
367 | typeof(val) __val = (val); \ | ||
368 | typeof(min) __min = (min); \ | ||
369 | typeof(max) __max = (max); \ | ||
370 | (void) (&__val == &__min); \ | ||
371 | (void) (&__val == &__max); \ | ||
372 | __val = __val < __min ? __min: __val; \ | ||
373 | __val > __max ? __max: __val; }) | ||
353 | 374 | ||
354 | /* | 375 | /* |
355 | * ..and if you can't take the strict | 376 | * ..and if you can't take the strict |
356 | * types, you can specify one yourself. | 377 | * types, you can specify one yourself. |
357 | * | 378 | * |
358 | * Or not use min/max at all, of course. | 379 | * Or not use min/max/clamp at all, of course. |
359 | */ | 380 | */ |
360 | #define min_t(type,x,y) \ | 381 | #define min_t(type, x, y) ({ \ |
361 | ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) | 382 | type __min1 = (x); \ |
362 | #define max_t(type,x,y) \ | 383 | type __min2 = (y); \ |
363 | ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) | 384 | __min1 < __min2 ? __min1: __min2; }) |
385 | |||
386 | #define max_t(type, x, y) ({ \ | ||
387 | type __max1 = (x); \ | ||
388 | type __max2 = (y); \ | ||
389 | __max1 > __max2 ? __max1: __max2; }) | ||
364 | 390 | ||
391 | /** | ||
392 | * clamp_t - return a value clamped to a given range using a given type | ||
393 | * @type: the type of variable to use | ||
394 | * @val: current value | ||
395 | * @min: minimum allowable value | ||
396 | * @max: maximum allowable value | ||
397 | * | ||
398 | * This macro does no typechecking and uses temporary variables of type | ||
399 | * 'type' to make all the comparisons. | ||
400 | */ | ||
401 | #define clamp_t(type, val, min, max) ({ \ | ||
402 | type __val = (val); \ | ||
403 | type __min = (min); \ | ||
404 | type __max = (max); \ | ||
405 | __val = __val < __min ? __min: __val; \ | ||
406 | __val > __max ? __max: __val; }) | ||
407 | |||
408 | /** | ||
409 | * clamp_val - return a value clamped to a given range using val's type | ||
410 | * @val: current value | ||
411 | * @min: minimum allowable value | ||
412 | * @max: maximum allowable value | ||
413 | * | ||
414 | * This macro does no typechecking and uses temporary variables of whatever | ||
415 | * type the input argument 'val' is. This is useful when val is an unsigned | ||
416 | * type and min and max are literals that will otherwise be assigned a signed | ||
417 | * integer type. | ||
418 | */ | ||
419 | #define clamp_val(val, min, max) ({ \ | ||
420 | typeof(val) __val = (val); \ | ||
421 | typeof(val) __min = (min); \ | ||
422 | typeof(val) __max = (max); \ | ||
423 | __val = __val < __min ? __min: __val; \ | ||
424 | __val > __max ? __max: __val; }) | ||
365 | 425 | ||
366 | /** | 426 | /** |
367 | * container_of - cast a member of a structure out to the containing structure | 427 | * container_of - cast a member of a structure out to the containing structure |