diff options
Diffstat (limited to 'include/linux/kernel.h')
| -rw-r--r-- | include/linux/kernel.h | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 5582410727cb..350dfb08aee3 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
| @@ -200,28 +200,28 @@ extern int _cond_resched(void); | |||
| 200 | 200 | ||
| 201 | #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) | 201 | #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) |
| 202 | 202 | ||
| 203 | /* | 203 | /** |
| 204 | * abs() handles unsigned and signed longs, ints, shorts and chars. For all | 204 | * abs - return absolute value of an argument |
| 205 | * input types abs() returns a signed long. | 205 | * @x: the value. If it is unsigned type, it is converted to signed type first |
| 206 | * abs() should not be used for 64-bit types (s64, u64, long long) - use abs64() | 206 | * (s64, long or int depending on its size). |
| 207 | * for those. | 207 | * |
| 208 | * Return: an absolute value of x. If x is 64-bit, macro's return type is s64, | ||
| 209 | * otherwise it is signed long. | ||
| 208 | */ | 210 | */ |
| 209 | #define abs(x) ({ \ | 211 | #define abs(x) __builtin_choose_expr(sizeof(x) == sizeof(s64), ({ \ |
| 210 | long ret; \ | 212 | s64 __x = (x); \ |
| 211 | if (sizeof(x) == sizeof(long)) { \ | 213 | (__x < 0) ? -__x : __x; \ |
| 212 | long __x = (x); \ | 214 | }), ({ \ |
| 213 | ret = (__x < 0) ? -__x : __x; \ | 215 | long ret; \ |
| 214 | } else { \ | 216 | if (sizeof(x) == sizeof(long)) { \ |
| 215 | int __x = (x); \ | 217 | long __x = (x); \ |
| 216 | ret = (__x < 0) ? -__x : __x; \ | 218 | ret = (__x < 0) ? -__x : __x; \ |
| 217 | } \ | 219 | } else { \ |
| 218 | ret; \ | 220 | int __x = (x); \ |
| 219 | }) | 221 | ret = (__x < 0) ? -__x : __x; \ |
| 220 | 222 | } \ | |
| 221 | #define abs64(x) ({ \ | 223 | ret; \ |
| 222 | s64 __x = (x); \ | 224 | })) |
| 223 | (__x < 0) ? -__x : __x; \ | ||
| 224 | }) | ||
| 225 | 225 | ||
| 226 | /** | 226 | /** |
| 227 | * reciprocal_scale - "scale" a value into range [0, ep_ro) | 227 | * reciprocal_scale - "scale" a value into range [0, ep_ro) |
| @@ -413,6 +413,8 @@ extern __printf(2, 3) | |||
| 413 | char *kasprintf(gfp_t gfp, const char *fmt, ...); | 413 | char *kasprintf(gfp_t gfp, const char *fmt, ...); |
| 414 | extern __printf(2, 0) | 414 | extern __printf(2, 0) |
| 415 | char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); | 415 | char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); |
| 416 | extern __printf(2, 0) | ||
| 417 | const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args); | ||
| 416 | 418 | ||
| 417 | extern __scanf(2, 3) | 419 | extern __scanf(2, 3) |
| 418 | int sscanf(const char *, const char *, ...); | 420 | int sscanf(const char *, const char *, ...); |
