diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2017-09-16 08:10:45 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2017-10-04 19:00:20 +0300 |
commit | 0a70fb4c1c180d6ad6cd4c1dcd3fae8c5d4dd62e (patch) | |
tree | b6f0c93e64ad4534e982ad28eaa599fa92f38e33 /include/linux | |
parent | 059a48096c883e98bc1a4a561abc0069f44cbfea (diff) | |
download | u-boot-0a70fb4c1c180d6ad6cd4c1dcd3fae8c5d4dd62e.tar.xz |
bug.h: move runtime BUG/WARN macros into <linux/bug.h>
Collect runtime BUG/WARN into a self-contained header <linux/bug.h>
to make these macros easier to use.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/bug.h | 28 | ||||
-rw-r--r-- | include/linux/compat.h | 15 |
2 files changed, 28 insertions, 15 deletions
diff --git a/include/linux/bug.h b/include/linux/bug.h index 133544ca46..f07bb716fc 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -1,6 +1,34 @@ #ifndef _LINUX_BUG_H #define _LINUX_BUG_H +#include <vsprintf.h> /* for panic() */ #include <linux/build_bug.h> +#include <linux/compiler.h> +#include <linux/printk.h> + +#define BUG() do { \ + printk("BUG at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ + panic("BUG!"); \ +} while (0) + +#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0) + +#define WARN_ON(condition) ({ \ + int __ret_warn_on = !!(condition); \ + if (unlikely(__ret_warn_on)) \ + printk("WARNING at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ + unlikely(__ret_warn_on); \ +}) + +#define WARN_ON_ONCE(condition) ({ \ + static bool __warned; \ + int __ret_warn_once = !!(condition); \ + \ + if (unlikely(__ret_warn_once && !__warned)) { \ + __warned = true; \ + WARN_ON(1); \ + } \ + unlikely(__ret_warn_once); \ +}) #endif /* _LINUX_BUG_H */ diff --git a/include/linux/compat.h b/include/linux/compat.h index bc027adcb9..1b3f089687 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -87,21 +87,6 @@ static inline void kmem_cache_destroy(struct kmem_cache *cachep) #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) -#ifndef BUG -#define BUG() do { \ - printf("U-Boot BUG at %s:%d!\n", __FILE__, __LINE__); \ -} while (0) - -#define BUG_ON(condition) do { if (condition) BUG(); } while(0) -#endif /* BUG */ - -#define WARN_ON(condition) ({ \ - int __ret_warn_on = !!(condition); \ - if (unlikely(__ret_warn_on)) \ - printf("WARNING in %s line %d\n", __FILE__, __LINE__); \ - unlikely(__ret_warn_on); \ -}) - #define PAGE_SIZE 4096 /* drivers/char/random.c */ |