]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
bug.h: move runtime BUG/WARN macros into <linux/bug.h>
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Sat, 16 Sep 2017 05:10:45 +0000 (14:10 +0900)
committerTom Rini <trini@konsulko.com>
Wed, 4 Oct 2017 16:00:20 +0000 (12:00 -0400)
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>
drivers/usb/dwc3/linux-compat.h
include/common.h
include/linux/bug.h
include/linux/compat.h

index 64db4ecc3c6f36b015b9f2d398646ca2290e1c5b..5cbe377e3cd9a17fa6b15c57d4c8efd35b4d8f86 100644 (file)
@@ -14,7 +14,6 @@
 
 #define WARN(val, format, arg...)      debug(format, ##arg)
 #define dev_WARN(dev, format, arg...)  debug(format, ##arg)
-#define WARN_ON_ONCE(val)              debug("Error %d\n", val)
 
 static inline size_t strlcat(char *dest, const char *src, size_t n)
 {
index 7ea78bde83f7b97fff36bcbc4fff91aecb495b47..18963355840d9890d7721807468cbce19ab872fc 100644 (file)
@@ -23,6 +23,7 @@ typedef volatile unsigned char        vu_char;
 #include <time.h>
 #include <asm-offsets.h>
 #include <linux/bitops.h>
+#include <linux/bug.h>
 #include <linux/delay.h>
 #include <linux/types.h>
 #include <linux/printk.h>
@@ -90,14 +91,6 @@ void __assert_fail(const char *assertion, const char *file, unsigned line,
        ({ if (!(x) && _DEBUG) \
                __assert_fail(#x, __FILE__, __LINE__, __func__); })
 
-#ifndef BUG
-#define BUG() do { \
-       printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
-       panic("BUG!"); \
-} while (0)
-#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
-#endif /* BUG */
-
 typedef void (interrupt_handler_t)(void *);
 
 #include <asm/u-boot.h> /* boot information for Linux kernel */
index 133544ca46f01d30d26e3afee573effc14755a50..f07bb716fc044bf7b68700b2fc1f481f25efe5d3 100644 (file)
@@ -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 */
index bc027adcb9368140a6aeb2d1eeaecb4191ac9345..1b3f089687e45629fe2d9b13a5da7752525cbe03 100644 (file)
@@ -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 */