blob: bbd75ac8b202920fa38076a9c4d296a215f36051 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Namhyung Kim02dfc8d2014-01-09 23:00:54 +09002#ifndef _TOOLS_ASM_BUG_H
3#define _TOOLS_ASM_BUG_H
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -02004
Namhyung Kim741a0c52014-01-09 23:00:55 +09005#include <linux/compiler.h>
6
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -02007#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
Matthew Wilcoxb246a9d2016-12-19 11:07:17 -050016#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
Matthew Wilcoxebb9a9a2016-12-14 15:07:56 -080024#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
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -020035#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})
Namhyung Kim02dfc8d2014-01-09 23:00:54 +090044
45#endif /* _TOOLS_ASM_BUG_H */