All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 7/8] bug.h: move runtime BUG/WARN macros into <linux/bug.h>
Date: Sat, 16 Sep 2017 14:10:45 +0900	[thread overview]
Message-ID: <1505538646-19191-8-git-send-email-yamada.masahiro@socionext.com> (raw)
In-Reply-To: <1505538646-19191-1-git-send-email-yamada.masahiro@socionext.com>

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>
---

Changes in v2: None

 drivers/usb/dwc3/linux-compat.h |  1 -
 include/common.h                |  9 +--------
 include/linux/bug.h             | 28 ++++++++++++++++++++++++++++
 include/linux/compat.h          | 15 ---------------
 4 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/drivers/usb/dwc3/linux-compat.h b/drivers/usb/dwc3/linux-compat.h
index 64db4ecc3c6f..5cbe377e3cd9 100644
--- a/drivers/usb/dwc3/linux-compat.h
+++ b/drivers/usb/dwc3/linux-compat.h
@@ -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)
 {
diff --git a/include/common.h b/include/common.h
index 7ea78bde83f7..18963355840d 100644
--- a/include/common.h
+++ b/include/common.h
@@ -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 */
diff --git a/include/linux/bug.h b/include/linux/bug.h
index 133544ca46f0..f07bb716fc04 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 bc027adcb936..1b3f089687e4 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@%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 */
-- 
2.7.4

  parent reply	other threads:[~2017-09-16  5:10 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-16  5:10 [U-Boot] [PATCH v2 0/8] Sync and consolidate Linux-derived printk, BUILD_BUG, BUG, WARN, etc Masahiro Yamada
2017-09-16  5:10 ` [U-Boot] [PATCH v2 1/8] stdio.h: move printf() stuff from <common.h> to <stdio.h> Masahiro Yamada
2017-10-05 21:51   ` [U-Boot] [U-Boot, v2, " Tom Rini
2017-09-16  5:10 ` [U-Boot] [PATCH v2 2/8] printk: collect printk stuff into <linux/printk.h> with loglevel support Masahiro Yamada
2017-10-05 21:52   ` [U-Boot] [U-Boot, v2, " Tom Rini
2017-09-16  5:10 ` [U-Boot] [PATCH v2 3/8] treewide: replace with error() with pr_err() Masahiro Yamada
2017-09-25  2:15   ` Simon Glass
2017-09-28  6:11   ` Masahiro Yamada
2017-09-28 12:43     ` Tom Rini
2017-09-28 12:56       ` Masahiro Yamada
2017-09-28 13:11         ` Tom Rini
2017-10-05 21:52   ` [U-Boot] [U-Boot, v2, " Tom Rini
2017-09-16  5:10 ` [U-Boot] [PATCH v2 4/8] common.h: remove error() Masahiro Yamada
2017-10-05 21:52   ` [U-Boot] [U-Boot,v2,4/8] " Tom Rini
2017-09-16  5:10 ` [U-Boot] [PATCH v2 5/8] vsprintf.h: include <linux/types.h> Masahiro Yamada
2017-10-05 21:52   ` [U-Boot] [U-Boot,v2,5/8] " Tom Rini
2017-09-16  5:10 ` [U-Boot] [PATCH v2 6/8] bug.h: sync BUILD_BUG stuff with Linux 4.13 Masahiro Yamada
2017-10-05 21:52   ` [U-Boot] [U-Boot, v2, " Tom Rini
2017-09-16  5:10 ` Masahiro Yamada [this message]
2017-10-05 21:52   ` [U-Boot] [U-Boot, v2, 7/8] bug.h: move runtime BUG/WARN macros into <linux/bug.h> Tom Rini
2017-09-16  5:10 ` [U-Boot] [PATCH v2 8/8] dm: define dev_*() log functions in DM header Masahiro Yamada
2017-09-25  2:15   ` Simon Glass
2017-09-26  3:00     ` Masahiro Yamada
2017-10-04  5:15 ` [U-Boot] [PATCH v2 0/8] Sync and consolidate Linux-derived printk, BUILD_BUG, BUG, WARN, etc Masahiro Yamada
2017-10-05  3:06   ` Tom Rini
2017-10-05  3:20     ` Masahiro Yamada
2017-10-05 11:58       ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1505538646-19191-8-git-send-email-yamada.masahiro@socionext.com \
    --to=yamada.masahiro@socionext.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.