diff options
Diffstat (limited to 'include/linux/kernel.h')
| -rw-r--r-- | include/linux/kernel.h | 96 |
1 files changed, 79 insertions, 17 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index cd6d02cf854d..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 | ||
| @@ -333,33 +338,90 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, | |||
| 333 | #endif /* __LITTLE_ENDIAN */ | 338 | #endif /* __LITTLE_ENDIAN */ |
| 334 | 339 | ||
| 335 | /* | 340 | /* |
| 336 | * min()/max() macros that also do | 341 | * min()/max()/clamp() macros that also do |
| 337 | * strict type-checking.. See the | 342 | * strict type-checking.. See the |
| 338 | * "unnecessary" pointer comparison. | 343 | * "unnecessary" pointer comparison. |
| 339 | */ | 344 | */ |
| 340 | #define min(x,y) ({ \ | 345 | #define min(x, y) ({ \ |
| 341 | typeof(x) _x = (x); \ | 346 | typeof(x) _min1 = (x); \ |
| 342 | typeof(y) _y = (y); \ | 347 | typeof(y) _min2 = (y); \ |
| 343 | (void) (&_x == &_y); \ | 348 | (void) (&_min1 == &_min2); \ |
| 344 | _x < _y ? _x : _y; }) | 349 | _min1 < _min2 ? _min1 : _min2; }) |
| 345 | 350 | ||
| 346 | #define max(x,y) ({ \ | 351 | #define max(x, y) ({ \ |
| 347 | typeof(x) _x = (x); \ | 352 | typeof(x) _max1 = (x); \ |
| 348 | typeof(y) _y = (y); \ | 353 | typeof(y) _max2 = (y); \ |
| 349 | (void) (&_x == &_y); \ | 354 | (void) (&_max1 == &_max2); \ |
| 350 | _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; }) | ||
| 351 | 374 | ||
| 352 | /* | 375 | /* |
| 353 | * ..and if you can't take the strict | 376 | * ..and if you can't take the strict |
| 354 | * types, you can specify one yourself. | 377 | * types, you can specify one yourself. |
| 355 | * | 378 | * |
| 356 | * Or not use min/max at all, of course. | 379 | * Or not use min/max/clamp at all, of course. |
| 380 | */ | ||
| 381 | #define min_t(type, x, y) ({ \ | ||
| 382 | type __min1 = (x); \ | ||
| 383 | type __min2 = (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; }) | ||
| 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. | ||
| 357 | */ | 400 | */ |
| 358 | #define min_t(type,x,y) \ | 401 | #define clamp_t(type, val, min, max) ({ \ |
| 359 | ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) | 402 | type __val = (val); \ |
| 360 | #define max_t(type,x,y) \ | 403 | type __min = (min); \ |
| 361 | ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) | 404 | type __max = (max); \ |
| 405 | __val = __val < __min ? __min: __val; \ | ||
| 406 | __val > __max ? __max: __val; }) | ||
| 362 | 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; }) | ||
| 363 | 425 | ||
| 364 | /** | 426 | /** |
| 365 | * 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 |
