Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[sfrench/cifs-2.6.git] / tools / include / asm / bug.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _TOOLS_ASM_BUG_H
3 #define _TOOLS_ASM_BUG_H
4
5 #include <linux/compiler.h>
6
7 #define __WARN_printf(arg...)   do { fprintf(stderr, arg); } while (0)
8
9 #define WARN(condition, format...) ({           \
10         int __ret_warn_on = !!(condition);      \
11         if (unlikely(__ret_warn_on))            \
12                 __WARN_printf(format);          \
13         unlikely(__ret_warn_on);                \
14 })
15
16 #define WARN_ON(condition) ({                                   \
17         int __ret_warn_on = !!(condition);                      \
18         if (unlikely(__ret_warn_on))                            \
19                 __WARN_printf("assertion failed at %s:%d\n",    \
20                                 __FILE__, __LINE__);            \
21         unlikely(__ret_warn_on);                                \
22 })
23
24 #define WARN_ON_ONCE(condition) ({                      \
25         static int __warned;                            \
26         int __ret_warn_once = !!(condition);            \
27                                                         \
28         if (unlikely(__ret_warn_once && !__warned)) {   \
29                 __warned = true;                        \
30                 WARN_ON(1);                             \
31         }                                               \
32         unlikely(__ret_warn_once);                      \
33 })
34
35 #define WARN_ONCE(condition, format...) ({      \
36         static int __warned;                    \
37         int __ret_warn_once = !!(condition);    \
38                                                 \
39         if (unlikely(__ret_warn_once))          \
40                 if (WARN(!__warned, format))    \
41                         __warned = 1;           \
42         unlikely(__ret_warn_once);              \
43 })
44
45 #endif /* _TOOLS_ASM_BUG_H */