bug.h 5.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5
#ifndef _ASM_GENERIC_BUG_H
#define _ASM_GENERIC_BUG_H

#include <linux/compiler.h>

M
Matt Mackall 已提交
6
#ifdef CONFIG_BUG
7 8 9 10

#ifdef CONFIG_GENERIC_BUG
#ifndef __ASSEMBLY__
struct bug_entry {
11
#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
12
	unsigned long	bug_addr;
13 14 15
#else
	signed int	bug_addr_disp;
#endif
16
#ifdef CONFIG_DEBUG_BUGVERBOSE
17
#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
18
	const char	*file;
19 20 21
#else
	signed int	file_disp;
#endif
22 23 24 25 26 27
	unsigned short	line;
#endif
	unsigned short	flags;
};
#endif		/* __ASSEMBLY__ */

28 29 30 31
#define BUGFLAG_WARNING		(1 << 0)
#define BUGFLAG_TAINT(taint)	(BUGFLAG_WARNING | ((taint) << 8))
#define BUG_GET_TAINT(bug)	((bug)->flags >> 8)

32 33
#endif	/* CONFIG_GENERIC_BUG */

34 35 36 37 38 39 40 41 42 43 44
/*
 * Don't use BUG() or BUG_ON() unless there's really no way out; one
 * example might be detecting data structure corruption in the middle
 * of an operation that can't be backed out of.  If the (sub)system
 * can somehow continue operating, perhaps with reduced functionality,
 * it's probably not BUG-worthy.
 *
 * If you're tempted to BUG(), think again:  is completely giving up
 * really the *only* solution?  There are usually better options, where
 * users don't need to reboot ASAP and can mostly shut down cleanly.
 */
L
Linus Torvalds 已提交
45 46
#ifndef HAVE_ARCH_BUG
#define BUG() do { \
47
	printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
L
Linus Torvalds 已提交
48 49 50 51 52
	panic("BUG!"); \
} while (0)
#endif

#ifndef HAVE_ARCH_BUG_ON
53
#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
L
Linus Torvalds 已提交
54 55
#endif

56 57 58 59 60 61
/*
 * WARN(), WARN_ON(), WARN_ON_ONCE, and so on can be used to report
 * significant issues that need prompt attention if they should ever
 * appear at runtime.  Use the versions with printk format strings
 * to provide better diagnostics.
 */
62
#ifndef __WARN_TAINT
63
#ifndef __ASSEMBLY__
64 65 66 67 68 69
extern __printf(3, 4)
void warn_slowpath_fmt(const char *file, const int line,
		       const char *fmt, ...);
extern __printf(4, 5)
void warn_slowpath_fmt_taint(const char *file, const int line, unsigned taint,
			     const char *fmt, ...);
70
extern void warn_slowpath_null(const char *file, const int line);
71 72
#define WANT_WARN_ON_SLOWPATH
#endif
73 74
#define __WARN()		warn_slowpath_null(__FILE__, __LINE__)
#define __WARN_printf(arg...)	warn_slowpath_fmt(__FILE__, __LINE__, arg)
75 76
#define __WARN_printf_taint(taint, arg...)				\
	warn_slowpath_fmt_taint(__FILE__, __LINE__, taint, arg)
77
#else
78
#define __WARN()		__WARN_TAINT(TAINT_WARN)
79
#define __WARN_printf(arg...)	do { printk(arg); __WARN(); } while (0)
80 81
#define __WARN_printf_taint(taint, arg...)				\
	do { printk(arg); __WARN_TAINT(taint); } while (0)
O
Olof Johansson 已提交
82 83 84
#endif

#ifndef WARN_ON
85
#define WARN_ON(condition) ({						\
L
Linus Torvalds 已提交
86
	int __ret_warn_on = !!(condition);				\
O
Olof Johansson 已提交
87 88
	if (unlikely(__ret_warn_on))					\
		__WARN();						\
89 90
	unlikely(__ret_warn_on);					\
})
L
Linus Torvalds 已提交
91 92
#endif

93 94 95 96 97 98 99 100 101
#ifndef WARN
#define WARN(condition, format...) ({						\
	int __ret_warn_on = !!(condition);				\
	if (unlikely(__ret_warn_on))					\
		__WARN_printf(format);					\
	unlikely(__ret_warn_on);					\
})
#endif

102 103 104 105 106 107 108
#define WARN_TAINT(condition, taint, format...) ({			\
	int __ret_warn_on = !!(condition);				\
	if (unlikely(__ret_warn_on))					\
		__WARN_printf_taint(taint, format);			\
	unlikely(__ret_warn_on);					\
})

M
Matt Mackall 已提交
109 110
#else /* !CONFIG_BUG */
#ifndef HAVE_ARCH_BUG
111
#define BUG() do {} while(0)
M
Matt Mackall 已提交
112 113 114 115 116 117 118
#endif

#ifndef HAVE_ARCH_BUG_ON
#define BUG_ON(condition) do { if (condition) ; } while(0)
#endif

#ifndef HAVE_ARCH_WARN_ON
119
#define WARN_ON(condition) ({						\
L
Linus Torvalds 已提交
120
	int __ret_warn_on = !!(condition);				\
121 122
	unlikely(__ret_warn_on);					\
})
M
Matt Mackall 已提交
123
#endif
124 125 126 127 128 129 130 131

#ifndef WARN
#define WARN(condition, format...) ({					\
	int __ret_warn_on = !!(condition);				\
	unlikely(__ret_warn_on);					\
})
#endif

132 133
#define WARN_TAINT(condition, taint, format...) WARN_ON(condition)

M
Matt Mackall 已提交
134 135
#endif

136
#define WARN_ON_ONCE(condition)	({				\
137
	static bool __section(.data.unlikely) __warned;		\
L
Linus Torvalds 已提交
138
	int __ret_warn_once = !!(condition);			\
139 140 141
								\
	if (unlikely(__ret_warn_once))				\
		if (WARN_ON(!__warned)) 			\
142
			__warned = true;			\
143
	unlikely(__ret_warn_once);				\
144 145
})

146
#define WARN_ONCE(condition, format...)	({			\
147
	static bool __section(.data.unlikely) __warned;		\
148 149 150 151
	int __ret_warn_once = !!(condition);			\
								\
	if (unlikely(__ret_warn_once))				\
		if (WARN(!__warned, format)) 			\
152
			__warned = true;			\
153 154 155
	unlikely(__ret_warn_once);				\
})

156
#define WARN_TAINT_ONCE(condition, taint, format...)	({	\
157
	static bool __section(.data.unlikely) __warned;		\
158 159 160 161 162 163 164 165
	int __ret_warn_once = !!(condition);			\
								\
	if (unlikely(__ret_warn_once))				\
		if (WARN_TAINT(!__warned, taint, format))	\
			__warned = true;			\
	unlikely(__ret_warn_once);				\
})

166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
/*
 * WARN_ON_SMP() is for cases that the warning is either
 * meaningless for !SMP or may even cause failures.
 * This is usually used for cases that we have
 * WARN_ON(!spin_is_locked(&lock)) checks, as spin_is_locked()
 * returns 0 for uniprocessor settings.
 * It can also be used with values that are only defined
 * on SMP:
 *
 * struct foo {
 *  [...]
 * #ifdef CONFIG_SMP
 *	int bar;
 * #endif
 * };
 *
 * void func(struct foo *zoot)
 * {
 *	WARN_ON_SMP(!zoot->bar);
 *
 * For CONFIG_SMP, WARN_ON_SMP() should act the same as WARN_ON(),
 * and should be a nop and return false for uniprocessor.
 *
 * if (WARN_ON_SMP(x)) returns true only when CONFIG_SMP is set
 * and x is true.
 */
192 193 194
#ifdef CONFIG_SMP
# define WARN_ON_SMP(x)			WARN_ON(x)
#else
195 196 197 198 199 200 201
/*
 * Use of ({0;}) because WARN_ON_SMP(x) may be used either as
 * a stand alone line statement or as a condition in an if ()
 * statement.
 * A simple "0" would cause gcc to give a "statement has no effect"
 * warning.
 */
202
# define WARN_ON_SMP(x)			({0;})
203 204
#endif

L
Linus Torvalds 已提交
205
#endif