^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef _ASM_GENERIC_BUG_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _ASM_GENERIC_BUG_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/instrumentation.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define CUT_HERE "------------[ cut here ]------------\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifdef CONFIG_GENERIC_BUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define BUGFLAG_WARNING (1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define BUGFLAG_ONCE (1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define BUGFLAG_DONE (1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define BUGFLAG_NO_CUT_HERE (1 << 3) /* CUT_HERE already sent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define BUGFLAG_TAINT(taint) ((taint) << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define BUG_GET_TAINT(bug) ((bug)->flags >> 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #ifndef __ASSEMBLY__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #ifdef CONFIG_BUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #ifdef CONFIG_GENERIC_BUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct bug_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) unsigned long bug_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) signed int bug_addr_disp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #ifdef CONFIG_DEBUG_BUGVERBOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) const char *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) signed int file_disp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) unsigned short line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) unsigned short flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #endif /* CONFIG_GENERIC_BUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * Don't use BUG() or BUG_ON() unless there's really no way out; one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * example might be detecting data structure corruption in the middle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * of an operation that can't be backed out of. If the (sub)system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * can somehow continue operating, perhaps with reduced functionality,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * it's probably not BUG-worthy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * If you're tempted to BUG(), think again: is completely giving up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * really the *only* solution? There are usually better options, where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * users don't need to reboot ASAP and can mostly shut down cleanly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #ifndef HAVE_ARCH_BUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define BUG() do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) barrier_before_unreachable(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) panic("BUG!"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #ifndef HAVE_ARCH_BUG_ON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * WARN(), WARN_ON(), WARN_ON_ONCE, and so on can be used to report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * significant kernel issues that need prompt attention if they should ever
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * appear at runtime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * Do not use these macros when checking for invalid external inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * (e.g. invalid system call arguments, or invalid data coming from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * network/devices), and on transient conditions like ENOMEM or EAGAIN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * These macros should be used for recoverable kernel issues only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * For invalid external inputs, transient conditions, etc use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * pr_err[_once/_ratelimited]() followed by dump_stack(), if necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * Do not include "BUG"/"WARNING" in format strings manually to make these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * conditions distinguishable from kernel issues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * Use the versions with printk format strings to provide better diagnostics.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #ifndef __WARN_FLAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) extern __printf(4, 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) void warn_slowpath_fmt(const char *file, const int line, unsigned taint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) const char *fmt, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define __WARN() __WARN_printf(TAINT_WARN, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define __WARN_printf(taint, arg...) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) instrumentation_begin(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) warn_slowpath_fmt(__FILE__, __LINE__, taint, arg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) instrumentation_end(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) extern __printf(1, 2) void __warn_printk(const char *fmt, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define __WARN() __WARN_FLAGS(BUGFLAG_TAINT(TAINT_WARN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define __WARN_printf(taint, arg...) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) instrumentation_begin(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) __warn_printk(arg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) __WARN_FLAGS(BUGFLAG_NO_CUT_HERE | BUGFLAG_TAINT(taint));\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) instrumentation_end(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define WARN_ON_ONCE(condition) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) int __ret_warn_on = !!(condition); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (unlikely(__ret_warn_on)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) __WARN_FLAGS(BUGFLAG_ONCE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) BUGFLAG_TAINT(TAINT_WARN)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) unlikely(__ret_warn_on); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /* used internally by panic.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct warn_args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct pt_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) void __warn(const char *file, int line, void *caller, unsigned taint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct pt_regs *regs, struct warn_args *args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #ifndef WARN_ON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define WARN_ON(condition) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) int __ret_warn_on = !!(condition); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (unlikely(__ret_warn_on)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) __WARN(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) unlikely(__ret_warn_on); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #ifndef WARN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #define WARN(condition, format...) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) int __ret_warn_on = !!(condition); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (unlikely(__ret_warn_on)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) __WARN_printf(TAINT_WARN, format); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unlikely(__ret_warn_on); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define WARN_TAINT(condition, taint, format...) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int __ret_warn_on = !!(condition); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (unlikely(__ret_warn_on)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) __WARN_printf(taint, format); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) unlikely(__ret_warn_on); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #ifndef WARN_ON_ONCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #define WARN_ON_ONCE(condition) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static bool __section(".data.once") __warned; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int __ret_warn_once = !!(condition); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (unlikely(__ret_warn_once && !__warned)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) __warned = true; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) WARN_ON(1); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) unlikely(__ret_warn_once); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define WARN_ONCE(condition, format...) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static bool __section(".data.once") __warned; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int __ret_warn_once = !!(condition); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (unlikely(__ret_warn_once && !__warned)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) __warned = true; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) WARN(1, format); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) unlikely(__ret_warn_once); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #define WARN_TAINT_ONCE(condition, taint, format...) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static bool __section(".data.once") __warned; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int __ret_warn_once = !!(condition); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (unlikely(__ret_warn_once && !__warned)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) __warned = true; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) WARN_TAINT(1, taint, format); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) unlikely(__ret_warn_once); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #else /* !CONFIG_BUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #ifndef HAVE_ARCH_BUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #define BUG() do {} while (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #ifndef HAVE_ARCH_BUG_ON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #ifndef HAVE_ARCH_WARN_ON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #define WARN_ON(condition) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) int __ret_warn_on = !!(condition); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) unlikely(__ret_warn_on); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #ifndef WARN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) #define WARN(condition, format...) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int __ret_warn_on = !!(condition); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) no_printk(format); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) unlikely(__ret_warn_on); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #define WARN_ON_ONCE(condition) WARN_ON(condition)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #define WARN_ONCE(condition, format...) WARN(condition, format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #define WARN_TAINT(condition, taint, format...) WARN(condition, format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #define WARN_TAINT_ONCE(condition, taint, format...) WARN(condition, format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * WARN_ON_SMP() is for cases that the warning is either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * meaningless for !SMP or may even cause failures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * It can also be used with values that are only defined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * on SMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * struct foo {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * [...]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * int bar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * void func(struct foo *zoot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * WARN_ON_SMP(!zoot->bar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * For CONFIG_SMP, WARN_ON_SMP() should act the same as WARN_ON(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * and should be a nop and return false for uniprocessor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * if (WARN_ON_SMP(x)) returns true only when CONFIG_SMP is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * and x is true.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) # define WARN_ON_SMP(x) WARN_ON(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * Use of ({0;}) because WARN_ON_SMP(x) may be used either as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * a stand alone line statement or as a condition in an if ()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * statement.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * A simple "0" would cause gcc to give a "statement has no effect"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * warning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) # define WARN_ON_SMP(x) ({0;})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #endif /* __ASSEMBLY__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #endif