bug.h 5.3 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
extern void warn_slowpath_fmt(const char *file, const int line,
65
		const char *fmt, ...) __attribute__((format(printf, 3, 4)));
66 67 68
extern void warn_slowpath_fmt_taint(const char *file, const int line,
				    unsigned taint, const char *fmt, ...)
	__attribute__((format(printf, 4, 5)));
69
extern void warn_slowpath_null(const char *file, const int line);
70 71
#define WANT_WARN_ON_SLOWPATH
#endif
72 73
#define __WARN()		warn_slowpath_null(__FILE__, __LINE__)
#define __WARN_printf(arg...)	warn_slowpath_fmt(__FILE__, __LINE__, arg)
74 75
#define __WARN_printf_taint(taint, arg...)				\
	warn_slowpath_fmt_taint(__FILE__, __LINE__, taint, arg)
76
#else
77
#define __WARN()		__WARN_TAINT(TAINT_WARN)
78
#define __WARN_printf(arg...)	do { printk(arg); __WARN(); } while (0)
79 80
#define __WARN_printf_taint(taint, arg...)				\
	do { printk(arg); __WARN_TAINT(taint); } while (0)
O
Olof Johansson 已提交
81 82 83
#endif

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

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

101 102 103 104 105 106 107
#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 已提交
108 109
#else /* !CONFIG_BUG */
#ifndef HAVE_ARCH_BUG
110
#define BUG() do {} while(0)
M
Matt Mackall 已提交
111 112 113 114 115 116 117
#endif

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

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

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

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

M
Matt Mackall 已提交
133 134
#endif

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

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

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

D
Dave Young 已提交
165 166 167
#define WARN_ON_RATELIMIT(condition, state)			\
		WARN_ON((condition) && __ratelimit(state))

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
/*
 * 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.
 */
194 195 196
#ifdef CONFIG_SMP
# define WARN_ON_SMP(x)			WARN_ON(x)
#else
197
# define WARN_ON_SMP(x)			({0;})
198 199
#endif

L
Linus Torvalds 已提交
200
#endif