xref: /linux/include/asm-generic/bug.h (revision 7ec7fb394298c212c30e063c57e0aa895efe9439)
1 #ifndef _ASM_GENERIC_BUG_H
2 #define _ASM_GENERIC_BUG_H
3 
4 #include <linux/compiler.h>
5 
6 #ifdef CONFIG_BUG
7 
8 #ifdef CONFIG_GENERIC_BUG
9 #ifndef __ASSEMBLY__
10 struct bug_entry {
11 #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
12 	unsigned long	bug_addr;
13 #else
14 	signed int	bug_addr_disp;
15 #endif
16 #ifdef CONFIG_DEBUG_BUGVERBOSE
17 #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
18 	const char	*file;
19 #else
20 	signed int	file_disp;
21 #endif
22 	unsigned short	line;
23 #endif
24 	unsigned short	flags;
25 };
26 #endif		/* __ASSEMBLY__ */
27 
28 #define BUGFLAG_WARNING	(1<<0)
29 #endif	/* CONFIG_GENERIC_BUG */
30 
31 #ifndef HAVE_ARCH_BUG
32 #define BUG() do { \
33 	printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
34 	panic("BUG!"); \
35 } while (0)
36 #endif
37 
38 #ifndef HAVE_ARCH_BUG_ON
39 #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
40 #endif
41 
42 #ifndef __WARN
43 #ifndef __ASSEMBLY__
44 extern void warn_slowpath(const char *file, const int line,
45 		const char *fmt, ...) __attribute__((format(printf, 3, 4)));
46 #define WANT_WARN_ON_SLOWPATH
47 #endif
48 #define __WARN()		warn_slowpath(__FILE__, __LINE__, NULL)
49 #define __WARN_printf(arg...)	warn_slowpath(__FILE__, __LINE__, arg)
50 #else
51 #define __WARN_printf(arg...)	do { printk(arg); __WARN(); } while (0)
52 #endif
53 
54 #ifndef WARN_ON
55 #define WARN_ON(condition) ({						\
56 	int __ret_warn_on = !!(condition);				\
57 	if (unlikely(__ret_warn_on))					\
58 		__WARN();						\
59 	unlikely(__ret_warn_on);					\
60 })
61 #endif
62 
63 #ifndef WARN
64 #define WARN(condition, format...) ({						\
65 	int __ret_warn_on = !!(condition);				\
66 	if (unlikely(__ret_warn_on))					\
67 		__WARN_printf(format);					\
68 	unlikely(__ret_warn_on);					\
69 })
70 #endif
71 
72 #else /* !CONFIG_BUG */
73 #ifndef HAVE_ARCH_BUG
74 #define BUG()
75 #endif
76 
77 #ifndef HAVE_ARCH_BUG_ON
78 #define BUG_ON(condition) do { if (condition) ; } while(0)
79 #endif
80 
81 #ifndef HAVE_ARCH_WARN_ON
82 #define WARN_ON(condition) ({						\
83 	int __ret_warn_on = !!(condition);				\
84 	unlikely(__ret_warn_on);					\
85 })
86 #endif
87 
88 #ifndef WARN
89 #define WARN(condition, format...) ({					\
90 	int __ret_warn_on = !!(condition);				\
91 	unlikely(__ret_warn_on);					\
92 })
93 #endif
94 
95 #endif
96 
97 #define WARN_ON_ONCE(condition)	({				\
98 	static int __warned;					\
99 	int __ret_warn_once = !!(condition);			\
100 								\
101 	if (unlikely(__ret_warn_once))				\
102 		if (WARN_ON(!__warned)) 			\
103 			__warned = 1;				\
104 	unlikely(__ret_warn_once);				\
105 })
106 
107 #define WARN_ONCE(condition, format...)	({			\
108 	static int __warned;					\
109 	int __ret_warn_once = !!(condition);			\
110 								\
111 	if (unlikely(__ret_warn_once))				\
112 		if (WARN(!__warned, format)) 			\
113 			__warned = 1;				\
114 	unlikely(__ret_warn_once);				\
115 })
116 
117 #define WARN_ON_RATELIMIT(condition, state)			\
118 		WARN_ON((condition) && __ratelimit(state))
119 
120 #ifdef CONFIG_SMP
121 # define WARN_ON_SMP(x)			WARN_ON(x)
122 #else
123 # define WARN_ON_SMP(x)			do { } while (0)
124 #endif
125 
126 #endif
127