| .. | .. |
|---|
| 10 | 10 | #include <linux/types.h> |
|---|
| 11 | 11 | #include <linux/compiler.h> |
|---|
| 12 | 12 | #include <linux/bitops.h> |
|---|
| 13 | +#include <linux/kstrtox.h> |
|---|
| 13 | 14 | #include <linux/log2.h> |
|---|
| 14 | 15 | #include <linux/minmax.h> |
|---|
| 15 | 16 | #include <linux/typecheck.h> |
|---|
| .. | .. |
|---|
| 46 | 47 | * @arr: array to be sized |
|---|
| 47 | 48 | */ |
|---|
| 48 | 49 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) |
|---|
| 50 | + |
|---|
| 51 | +#define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) |
|---|
| 49 | 52 | |
|---|
| 50 | 53 | #define u64_to_user_ptr(x) ( \ |
|---|
| 51 | 54 | { \ |
|---|
| .. | .. |
|---|
| 320 | 323 | __printf(1, 2) |
|---|
| 321 | 324 | void panic(const char *fmt, ...) __noreturn __cold; |
|---|
| 322 | 325 | void nmi_panic(struct pt_regs *regs, const char *msg); |
|---|
| 326 | +void check_panic_on_warn(const char *origin); |
|---|
| 323 | 327 | extern void oops_enter(void); |
|---|
| 324 | 328 | extern void oops_exit(void); |
|---|
| 325 | 329 | extern bool oops_may_print(void); |
|---|
| 326 | 330 | void do_exit(long error_code) __noreturn; |
|---|
| 327 | 331 | void complete_and_exit(struct completion *, long) __noreturn; |
|---|
| 328 | | - |
|---|
| 329 | | -/* Internal, do not use. */ |
|---|
| 330 | | -int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res); |
|---|
| 331 | | -int __must_check _kstrtol(const char *s, unsigned int base, long *res); |
|---|
| 332 | | - |
|---|
| 333 | | -int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res); |
|---|
| 334 | | -int __must_check kstrtoll(const char *s, unsigned int base, long long *res); |
|---|
| 335 | | - |
|---|
| 336 | | -/** |
|---|
| 337 | | - * kstrtoul - convert a string to an unsigned long |
|---|
| 338 | | - * @s: The start of the string. The string must be null-terminated, and may also |
|---|
| 339 | | - * include a single newline before its terminating null. The first character |
|---|
| 340 | | - * may also be a plus sign, but not a minus sign. |
|---|
| 341 | | - * @base: The number base to use. The maximum supported base is 16. If base is |
|---|
| 342 | | - * given as 0, then the base of the string is automatically detected with the |
|---|
| 343 | | - * conventional semantics - If it begins with 0x the number will be parsed as a |
|---|
| 344 | | - * hexadecimal (case insensitive), if it otherwise begins with 0, it will be |
|---|
| 345 | | - * parsed as an octal number. Otherwise it will be parsed as a decimal. |
|---|
| 346 | | - * @res: Where to write the result of the conversion on success. |
|---|
| 347 | | - * |
|---|
| 348 | | - * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. |
|---|
| 349 | | - * Preferred over simple_strtoul(). Return code must be checked. |
|---|
| 350 | | -*/ |
|---|
| 351 | | -static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res) |
|---|
| 352 | | -{ |
|---|
| 353 | | - /* |
|---|
| 354 | | - * We want to shortcut function call, but |
|---|
| 355 | | - * __builtin_types_compatible_p(unsigned long, unsigned long long) = 0. |
|---|
| 356 | | - */ |
|---|
| 357 | | - if (sizeof(unsigned long) == sizeof(unsigned long long) && |
|---|
| 358 | | - __alignof__(unsigned long) == __alignof__(unsigned long long)) |
|---|
| 359 | | - return kstrtoull(s, base, (unsigned long long *)res); |
|---|
| 360 | | - else |
|---|
| 361 | | - return _kstrtoul(s, base, res); |
|---|
| 362 | | -} |
|---|
| 363 | | - |
|---|
| 364 | | -/** |
|---|
| 365 | | - * kstrtol - convert a string to a long |
|---|
| 366 | | - * @s: The start of the string. The string must be null-terminated, and may also |
|---|
| 367 | | - * include a single newline before its terminating null. The first character |
|---|
| 368 | | - * may also be a plus sign or a minus sign. |
|---|
| 369 | | - * @base: The number base to use. The maximum supported base is 16. If base is |
|---|
| 370 | | - * given as 0, then the base of the string is automatically detected with the |
|---|
| 371 | | - * conventional semantics - If it begins with 0x the number will be parsed as a |
|---|
| 372 | | - * hexadecimal (case insensitive), if it otherwise begins with 0, it will be |
|---|
| 373 | | - * parsed as an octal number. Otherwise it will be parsed as a decimal. |
|---|
| 374 | | - * @res: Where to write the result of the conversion on success. |
|---|
| 375 | | - * |
|---|
| 376 | | - * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. |
|---|
| 377 | | - * Preferred over simple_strtol(). Return code must be checked. |
|---|
| 378 | | - */ |
|---|
| 379 | | -static inline int __must_check kstrtol(const char *s, unsigned int base, long *res) |
|---|
| 380 | | -{ |
|---|
| 381 | | - /* |
|---|
| 382 | | - * We want to shortcut function call, but |
|---|
| 383 | | - * __builtin_types_compatible_p(long, long long) = 0. |
|---|
| 384 | | - */ |
|---|
| 385 | | - if (sizeof(long) == sizeof(long long) && |
|---|
| 386 | | - __alignof__(long) == __alignof__(long long)) |
|---|
| 387 | | - return kstrtoll(s, base, (long long *)res); |
|---|
| 388 | | - else |
|---|
| 389 | | - return _kstrtol(s, base, res); |
|---|
| 390 | | -} |
|---|
| 391 | | - |
|---|
| 392 | | -int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res); |
|---|
| 393 | | -int __must_check kstrtoint(const char *s, unsigned int base, int *res); |
|---|
| 394 | | - |
|---|
| 395 | | -static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res) |
|---|
| 396 | | -{ |
|---|
| 397 | | - return kstrtoull(s, base, res); |
|---|
| 398 | | -} |
|---|
| 399 | | - |
|---|
| 400 | | -static inline int __must_check kstrtos64(const char *s, unsigned int base, s64 *res) |
|---|
| 401 | | -{ |
|---|
| 402 | | - return kstrtoll(s, base, res); |
|---|
| 403 | | -} |
|---|
| 404 | | - |
|---|
| 405 | | -static inline int __must_check kstrtou32(const char *s, unsigned int base, u32 *res) |
|---|
| 406 | | -{ |
|---|
| 407 | | - return kstrtouint(s, base, res); |
|---|
| 408 | | -} |
|---|
| 409 | | - |
|---|
| 410 | | -static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *res) |
|---|
| 411 | | -{ |
|---|
| 412 | | - return kstrtoint(s, base, res); |
|---|
| 413 | | -} |
|---|
| 414 | | - |
|---|
| 415 | | -int __must_check kstrtou16(const char *s, unsigned int base, u16 *res); |
|---|
| 416 | | -int __must_check kstrtos16(const char *s, unsigned int base, s16 *res); |
|---|
| 417 | | -int __must_check kstrtou8(const char *s, unsigned int base, u8 *res); |
|---|
| 418 | | -int __must_check kstrtos8(const char *s, unsigned int base, s8 *res); |
|---|
| 419 | | -int __must_check kstrtobool(const char *s, bool *res); |
|---|
| 420 | | - |
|---|
| 421 | | -int __must_check kstrtoull_from_user(const char __user *s, size_t count, unsigned int base, unsigned long long *res); |
|---|
| 422 | | -int __must_check kstrtoll_from_user(const char __user *s, size_t count, unsigned int base, long long *res); |
|---|
| 423 | | -int __must_check kstrtoul_from_user(const char __user *s, size_t count, unsigned int base, unsigned long *res); |
|---|
| 424 | | -int __must_check kstrtol_from_user(const char __user *s, size_t count, unsigned int base, long *res); |
|---|
| 425 | | -int __must_check kstrtouint_from_user(const char __user *s, size_t count, unsigned int base, unsigned int *res); |
|---|
| 426 | | -int __must_check kstrtoint_from_user(const char __user *s, size_t count, unsigned int base, int *res); |
|---|
| 427 | | -int __must_check kstrtou16_from_user(const char __user *s, size_t count, unsigned int base, u16 *res); |
|---|
| 428 | | -int __must_check kstrtos16_from_user(const char __user *s, size_t count, unsigned int base, s16 *res); |
|---|
| 429 | | -int __must_check kstrtou8_from_user(const char __user *s, size_t count, unsigned int base, u8 *res); |
|---|
| 430 | | -int __must_check kstrtos8_from_user(const char __user *s, size_t count, unsigned int base, s8 *res); |
|---|
| 431 | | -int __must_check kstrtobool_from_user(const char __user *s, size_t count, bool *res); |
|---|
| 432 | | - |
|---|
| 433 | | -static inline int __must_check kstrtou64_from_user(const char __user *s, size_t count, unsigned int base, u64 *res) |
|---|
| 434 | | -{ |
|---|
| 435 | | - return kstrtoull_from_user(s, count, base, res); |
|---|
| 436 | | -} |
|---|
| 437 | | - |
|---|
| 438 | | -static inline int __must_check kstrtos64_from_user(const char __user *s, size_t count, unsigned int base, s64 *res) |
|---|
| 439 | | -{ |
|---|
| 440 | | - return kstrtoll_from_user(s, count, base, res); |
|---|
| 441 | | -} |
|---|
| 442 | | - |
|---|
| 443 | | -static inline int __must_check kstrtou32_from_user(const char __user *s, size_t count, unsigned int base, u32 *res) |
|---|
| 444 | | -{ |
|---|
| 445 | | - return kstrtouint_from_user(s, count, base, res); |
|---|
| 446 | | -} |
|---|
| 447 | | - |
|---|
| 448 | | -static inline int __must_check kstrtos32_from_user(const char __user *s, size_t count, unsigned int base, s32 *res) |
|---|
| 449 | | -{ |
|---|
| 450 | | - return kstrtoint_from_user(s, count, base, res); |
|---|
| 451 | | -} |
|---|
| 452 | | - |
|---|
| 453 | | -/* |
|---|
| 454 | | - * Use kstrto<foo> instead. |
|---|
| 455 | | - * |
|---|
| 456 | | - * NOTE: simple_strto<foo> does not check for the range overflow and, |
|---|
| 457 | | - * depending on the input, may give interesting results. |
|---|
| 458 | | - * |
|---|
| 459 | | - * Use these functions if and only if you cannot use kstrto<foo>, because |
|---|
| 460 | | - * the conversion ends on the first non-digit character, which may be far |
|---|
| 461 | | - * beyond the supported range. It might be useful to parse the strings like |
|---|
| 462 | | - * 10x50 or 12:21 without altering original string or temporary buffer in use. |
|---|
| 463 | | - * Keep in mind above caveat. |
|---|
| 464 | | - */ |
|---|
| 465 | | - |
|---|
| 466 | | -extern unsigned long simple_strtoul(const char *,char **,unsigned int); |
|---|
| 467 | | -extern long simple_strtol(const char *,char **,unsigned int); |
|---|
| 468 | | -extern unsigned long long simple_strtoull(const char *,char **,unsigned int); |
|---|
| 469 | | -extern long long simple_strtoll(const char *,char **,unsigned int); |
|---|
| 470 | 332 | |
|---|
| 471 | 333 | extern int num_to_str(char *buf, int size, |
|---|
| 472 | 334 | unsigned long long num, unsigned int width); |
|---|
| .. | .. |
|---|
| 519 | 381 | return (u32)int_sqrt(x); |
|---|
| 520 | 382 | } |
|---|
| 521 | 383 | #endif |
|---|
| 522 | | - |
|---|
| 523 | | -#ifdef CONFIG_SMP |
|---|
| 524 | | -extern unsigned int sysctl_oops_all_cpu_backtrace; |
|---|
| 525 | | -#else |
|---|
| 526 | | -#define sysctl_oops_all_cpu_backtrace 0 |
|---|
| 527 | | -#endif /* CONFIG_SMP */ |
|---|
| 528 | 384 | |
|---|
| 529 | 385 | extern void bust_spinlocks(int yes); |
|---|
| 530 | 386 | extern int panic_timeout; |
|---|