hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/include/linux/kernel.h
....@@ -10,6 +10,7 @@
1010 #include <linux/types.h>
1111 #include <linux/compiler.h>
1212 #include <linux/bitops.h>
13
+#include <linux/kstrtox.h>
1314 #include <linux/log2.h>
1415 #include <linux/minmax.h>
1516 #include <linux/typecheck.h>
....@@ -46,6 +47,8 @@
4647 * @arr: array to be sized
4748 */
4849 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
50
+
51
+#define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL)
4952
5053 #define u64_to_user_ptr(x) ( \
5154 { \
....@@ -204,7 +207,6 @@
204207 extern void ___might_sleep(const char *file, int line, int preempt_offset);
205208 extern void __might_sleep(const char *file, int line, int preempt_offset);
206209 extern void __cant_sleep(const char *file, int line, int preempt_offset);
207
-extern void __cant_migrate(const char *file, int line);
208210
209211 /**
210212 * might_sleep - annotation for functions that can sleep
....@@ -220,10 +222,6 @@
220222 */
221223 # define might_sleep() \
222224 do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
223
-
224
-# define might_sleep_no_state_check() \
225
- do { ___might_sleep(__FILE__, __LINE__, 0); } while (0)
226
-
227225 /**
228226 * cant_sleep - annotation for functions that cannot sleep
229227 *
....@@ -232,18 +230,6 @@
232230 # define cant_sleep() \
233231 do { __cant_sleep(__FILE__, __LINE__, 0); } while (0)
234232 # define sched_annotate_sleep() (current->task_state_change = 0)
235
-
236
-/**
237
- * cant_migrate - annotation for functions that cannot migrate
238
- *
239
- * Will print a stack trace if executed in code which is migratable
240
- */
241
-# define cant_migrate() \
242
- do { \
243
- if (IS_ENABLED(CONFIG_SMP)) \
244
- __cant_migrate(__FILE__, __LINE__); \
245
- } while (0)
246
-
247233 /**
248234 * non_block_start - annotate the start of section where sleeping is prohibited
249235 *
....@@ -267,15 +253,20 @@
267253 static inline void __might_sleep(const char *file, int line,
268254 int preempt_offset) { }
269255 # define might_sleep() do { might_resched(); } while (0)
270
-# define might_sleep_no_state_check() do { might_resched(); } while (0)
271256 # define cant_sleep() do { } while (0)
272
-# define cant_migrate() do { } while (0)
273257 # define sched_annotate_sleep() do { } while (0)
274258 # define non_block_start() do { } while (0)
275259 # define non_block_end() do { } while (0)
276260 #endif
277261
278262 #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
263
+
264
+#ifndef CONFIG_PREEMPT_RT
265
+# define cant_migrate() cant_sleep()
266
+#else
267
+ /* Placeholder for now */
268
+# define cant_migrate() do { } while (0)
269
+#endif
279270
280271 /**
281272 * abs - return absolute value of an argument
....@@ -332,153 +323,12 @@
332323 __printf(1, 2)
333324 void panic(const char *fmt, ...) __noreturn __cold;
334325 void nmi_panic(struct pt_regs *regs, const char *msg);
326
+void check_panic_on_warn(const char *origin);
335327 extern void oops_enter(void);
336328 extern void oops_exit(void);
337329 extern bool oops_may_print(void);
338330 void do_exit(long error_code) __noreturn;
339331 void complete_and_exit(struct completion *, long) __noreturn;
340
-
341
-/* Internal, do not use. */
342
-int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res);
343
-int __must_check _kstrtol(const char *s, unsigned int base, long *res);
344
-
345
-int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
346
-int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
347
-
348
-/**
349
- * kstrtoul - convert a string to an unsigned long
350
- * @s: The start of the string. The string must be null-terminated, and may also
351
- * include a single newline before its terminating null. The first character
352
- * may also be a plus sign, but not a minus sign.
353
- * @base: The number base to use. The maximum supported base is 16. If base is
354
- * given as 0, then the base of the string is automatically detected with the
355
- * conventional semantics - If it begins with 0x the number will be parsed as a
356
- * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
357
- * parsed as an octal number. Otherwise it will be parsed as a decimal.
358
- * @res: Where to write the result of the conversion on success.
359
- *
360
- * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
361
- * Preferred over simple_strtoul(). Return code must be checked.
362
-*/
363
-static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res)
364
-{
365
- /*
366
- * We want to shortcut function call, but
367
- * __builtin_types_compatible_p(unsigned long, unsigned long long) = 0.
368
- */
369
- if (sizeof(unsigned long) == sizeof(unsigned long long) &&
370
- __alignof__(unsigned long) == __alignof__(unsigned long long))
371
- return kstrtoull(s, base, (unsigned long long *)res);
372
- else
373
- return _kstrtoul(s, base, res);
374
-}
375
-
376
-/**
377
- * kstrtol - convert a string to a long
378
- * @s: The start of the string. The string must be null-terminated, and may also
379
- * include a single newline before its terminating null. The first character
380
- * may also be a plus sign or a minus sign.
381
- * @base: The number base to use. The maximum supported base is 16. If base is
382
- * given as 0, then the base of the string is automatically detected with the
383
- * conventional semantics - If it begins with 0x the number will be parsed as a
384
- * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
385
- * parsed as an octal number. Otherwise it will be parsed as a decimal.
386
- * @res: Where to write the result of the conversion on success.
387
- *
388
- * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
389
- * Preferred over simple_strtol(). Return code must be checked.
390
- */
391
-static inline int __must_check kstrtol(const char *s, unsigned int base, long *res)
392
-{
393
- /*
394
- * We want to shortcut function call, but
395
- * __builtin_types_compatible_p(long, long long) = 0.
396
- */
397
- if (sizeof(long) == sizeof(long long) &&
398
- __alignof__(long) == __alignof__(long long))
399
- return kstrtoll(s, base, (long long *)res);
400
- else
401
- return _kstrtol(s, base, res);
402
-}
403
-
404
-int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res);
405
-int __must_check kstrtoint(const char *s, unsigned int base, int *res);
406
-
407
-static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res)
408
-{
409
- return kstrtoull(s, base, res);
410
-}
411
-
412
-static inline int __must_check kstrtos64(const char *s, unsigned int base, s64 *res)
413
-{
414
- return kstrtoll(s, base, res);
415
-}
416
-
417
-static inline int __must_check kstrtou32(const char *s, unsigned int base, u32 *res)
418
-{
419
- return kstrtouint(s, base, res);
420
-}
421
-
422
-static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *res)
423
-{
424
- return kstrtoint(s, base, res);
425
-}
426
-
427
-int __must_check kstrtou16(const char *s, unsigned int base, u16 *res);
428
-int __must_check kstrtos16(const char *s, unsigned int base, s16 *res);
429
-int __must_check kstrtou8(const char *s, unsigned int base, u8 *res);
430
-int __must_check kstrtos8(const char *s, unsigned int base, s8 *res);
431
-int __must_check kstrtobool(const char *s, bool *res);
432
-
433
-int __must_check kstrtoull_from_user(const char __user *s, size_t count, unsigned int base, unsigned long long *res);
434
-int __must_check kstrtoll_from_user(const char __user *s, size_t count, unsigned int base, long long *res);
435
-int __must_check kstrtoul_from_user(const char __user *s, size_t count, unsigned int base, unsigned long *res);
436
-int __must_check kstrtol_from_user(const char __user *s, size_t count, unsigned int base, long *res);
437
-int __must_check kstrtouint_from_user(const char __user *s, size_t count, unsigned int base, unsigned int *res);
438
-int __must_check kstrtoint_from_user(const char __user *s, size_t count, unsigned int base, int *res);
439
-int __must_check kstrtou16_from_user(const char __user *s, size_t count, unsigned int base, u16 *res);
440
-int __must_check kstrtos16_from_user(const char __user *s, size_t count, unsigned int base, s16 *res);
441
-int __must_check kstrtou8_from_user(const char __user *s, size_t count, unsigned int base, u8 *res);
442
-int __must_check kstrtos8_from_user(const char __user *s, size_t count, unsigned int base, s8 *res);
443
-int __must_check kstrtobool_from_user(const char __user *s, size_t count, bool *res);
444
-
445
-static inline int __must_check kstrtou64_from_user(const char __user *s, size_t count, unsigned int base, u64 *res)
446
-{
447
- return kstrtoull_from_user(s, count, base, res);
448
-}
449
-
450
-static inline int __must_check kstrtos64_from_user(const char __user *s, size_t count, unsigned int base, s64 *res)
451
-{
452
- return kstrtoll_from_user(s, count, base, res);
453
-}
454
-
455
-static inline int __must_check kstrtou32_from_user(const char __user *s, size_t count, unsigned int base, u32 *res)
456
-{
457
- return kstrtouint_from_user(s, count, base, res);
458
-}
459
-
460
-static inline int __must_check kstrtos32_from_user(const char __user *s, size_t count, unsigned int base, s32 *res)
461
-{
462
- return kstrtoint_from_user(s, count, base, res);
463
-}
464
-
465
-/*
466
- * Use kstrto<foo> instead.
467
- *
468
- * NOTE: simple_strto<foo> does not check for the range overflow and,
469
- * depending on the input, may give interesting results.
470
- *
471
- * Use these functions if and only if you cannot use kstrto<foo>, because
472
- * the conversion ends on the first non-digit character, which may be far
473
- * beyond the supported range. It might be useful to parse the strings like
474
- * 10x50 or 12:21 without altering original string or temporary buffer in use.
475
- * Keep in mind above caveat.
476
- */
477
-
478
-extern unsigned long simple_strtoul(const char *,char **,unsigned int);
479
-extern long simple_strtol(const char *,char **,unsigned int);
480
-extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
481
-extern long long simple_strtoll(const char *,char **,unsigned int);
482332
483333 extern int num_to_str(char *buf, int size,
484334 unsigned long long num, unsigned int width);
....@@ -531,12 +381,6 @@
531381 return (u32)int_sqrt(x);
532382 }
533383 #endif
534
-
535
-#ifdef CONFIG_SMP
536
-extern unsigned int sysctl_oops_all_cpu_backtrace;
537
-#else
538
-#define sysctl_oops_all_cpu_backtrace 0
539
-#endif /* CONFIG_SMP */
540384
541385 extern void bust_spinlocks(int yes);
542386 extern int panic_timeout;