diff options
Diffstat (limited to 'include/linux/kernel.h')
| -rw-r--r-- | include/linux/kernel.h | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 7d8dfc7392f1..c566927efcbd 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
| @@ -77,13 +77,15 @@ | |||
| 77 | 77 | ||
| 78 | /* | 78 | /* |
| 79 | * Divide positive or negative dividend by positive divisor and round | 79 | * Divide positive or negative dividend by positive divisor and round |
| 80 | * to closest integer. Result is undefined for negative divisors. | 80 | * to closest integer. Result is undefined for negative divisors and |
| 81 | * for negative dividends if the divisor variable type is unsigned. | ||
| 81 | */ | 82 | */ |
| 82 | #define DIV_ROUND_CLOSEST(x, divisor)( \ | 83 | #define DIV_ROUND_CLOSEST(x, divisor)( \ |
| 83 | { \ | 84 | { \ |
| 84 | typeof(x) __x = x; \ | 85 | typeof(x) __x = x; \ |
| 85 | typeof(divisor) __d = divisor; \ | 86 | typeof(divisor) __d = divisor; \ |
| 86 | (((typeof(x))-1) > 0 || (__x) > 0) ? \ | 87 | (((typeof(x))-1) > 0 || \ |
| 88 | ((typeof(divisor))-1) > 0 || (__x) > 0) ? \ | ||
| 87 | (((__x) + ((__d) / 2)) / (__d)) : \ | 89 | (((__x) + ((__d) / 2)) / (__d)) : \ |
| 88 | (((__x) - ((__d) / 2)) / (__d)); \ | 90 | (((__x) - ((__d) / 2)) / (__d)); \ |
| 89 | } \ | 91 | } \ |
| @@ -220,6 +222,23 @@ int __must_check _kstrtol(const char *s, unsigned int base, long *res); | |||
| 220 | 222 | ||
| 221 | int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res); | 223 | int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res); |
| 222 | int __must_check kstrtoll(const char *s, unsigned int base, long long *res); | 224 | int __must_check kstrtoll(const char *s, unsigned int base, long long *res); |
| 225 | |||
| 226 | /** | ||
| 227 | * kstrtoul - convert a string to an unsigned long | ||
| 228 | * @s: The start of the string. The string must be null-terminated, and may also | ||
| 229 | * include a single newline before its terminating null. The first character | ||
| 230 | * may also be a plus sign, but not a minus sign. | ||
| 231 | * @base: The number base to use. The maximum supported base is 16. If base is | ||
| 232 | * given as 0, then the base of the string is automatically detected with the | ||
| 233 | * conventional semantics - If it begins with 0x the number will be parsed as a | ||
| 234 | * hexadecimal (case insensitive), if it otherwise begins with 0, it will be | ||
| 235 | * parsed as an octal number. Otherwise it will be parsed as a decimal. | ||
| 236 | * @res: Where to write the result of the conversion on success. | ||
| 237 | * | ||
| 238 | * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. | ||
| 239 | * Used as a replacement for the obsolete simple_strtoull. Return code must | ||
| 240 | * be checked. | ||
| 241 | */ | ||
| 223 | static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res) | 242 | static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res) |
| 224 | { | 243 | { |
| 225 | /* | 244 | /* |
| @@ -233,6 +252,22 @@ static inline int __must_check kstrtoul(const char *s, unsigned int base, unsign | |||
| 233 | return _kstrtoul(s, base, res); | 252 | return _kstrtoul(s, base, res); |
| 234 | } | 253 | } |
| 235 | 254 | ||
| 255 | /** | ||
| 256 | * kstrtol - convert a string to a long | ||
| 257 | * @s: The start of the string. The string must be null-terminated, and may also | ||
| 258 | * include a single newline before its terminating null. The first character | ||
| 259 | * may also be a plus sign or a minus sign. | ||
| 260 | * @base: The number base to use. The maximum supported base is 16. If base is | ||
| 261 | * given as 0, then the base of the string is automatically detected with the | ||
| 262 | * conventional semantics - If it begins with 0x the number will be parsed as a | ||
| 263 | * hexadecimal (case insensitive), if it otherwise begins with 0, it will be | ||
| 264 | * parsed as an octal number. Otherwise it will be parsed as a decimal. | ||
| 265 | * @res: Where to write the result of the conversion on success. | ||
| 266 | * | ||
| 267 | * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. | ||
| 268 | * Used as a replacement for the obsolete simple_strtoull. Return code must | ||
| 269 | * be checked. | ||
| 270 | */ | ||
| 236 | static inline int __must_check kstrtol(const char *s, unsigned int base, long *res) | 271 | static inline int __must_check kstrtol(const char *s, unsigned int base, long *res) |
| 237 | { | 272 | { |
| 238 | /* | 273 | /* |
| @@ -527,9 +562,6 @@ __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap); | |||
| 527 | 562 | ||
| 528 | extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode); | 563 | extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode); |
| 529 | #else | 564 | #else |
| 530 | static inline __printf(1, 2) | ||
| 531 | int trace_printk(const char *fmt, ...); | ||
| 532 | |||
| 533 | static inline void tracing_start(void) { } | 565 | static inline void tracing_start(void) { } |
| 534 | static inline void tracing_stop(void) { } | 566 | static inline void tracing_stop(void) { } |
| 535 | static inline void ftrace_off_permanent(void) { } | 567 | static inline void ftrace_off_permanent(void) { } |
| @@ -539,8 +571,8 @@ static inline void tracing_on(void) { } | |||
| 539 | static inline void tracing_off(void) { } | 571 | static inline void tracing_off(void) { } |
| 540 | static inline int tracing_is_on(void) { return 0; } | 572 | static inline int tracing_is_on(void) { return 0; } |
| 541 | 573 | ||
| 542 | static inline int | 574 | static inline __printf(1, 2) |
| 543 | trace_printk(const char *fmt, ...) | 575 | int trace_printk(const char *fmt, ...) |
| 544 | { | 576 | { |
| 545 | return 0; | 577 | return 0; |
| 546 | } | 578 | } |
| @@ -687,20 +719,6 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } | |||
| 687 | /* Trap pasters of __FUNCTION__ at compile-time */ | 719 | /* Trap pasters of __FUNCTION__ at compile-time */ |
| 688 | #define __FUNCTION__ (__func__) | 720 | #define __FUNCTION__ (__func__) |
| 689 | 721 | ||
| 690 | /* This helps us to avoid #ifdef CONFIG_NUMA */ | ||
| 691 | #ifdef CONFIG_NUMA | ||
| 692 | #define NUMA_BUILD 1 | ||
| 693 | #else | ||
| 694 | #define NUMA_BUILD 0 | ||
| 695 | #endif | ||
| 696 | |||
| 697 | /* This helps us avoid #ifdef CONFIG_COMPACTION */ | ||
| 698 | #ifdef CONFIG_COMPACTION | ||
| 699 | #define COMPACTION_BUILD 1 | ||
| 700 | #else | ||
| 701 | #define COMPACTION_BUILD 0 | ||
| 702 | #endif | ||
| 703 | |||
| 704 | /* This helps us to avoid #ifdef CONFIG_SYMBOL_PREFIX */ | 722 | /* This helps us to avoid #ifdef CONFIG_SYMBOL_PREFIX */ |
| 705 | #ifdef CONFIG_SYMBOL_PREFIX | 723 | #ifdef CONFIG_SYMBOL_PREFIX |
| 706 | #define SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX | 724 | #define SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX |
