
BUG(), BUG_ON(), WARN_ON(), etc. are generally used to test a condition that should never happen. If it does, it is a bug, then they print noisy messages.
They are useful to catch bugs, and Linux always enables them, but doing so in U-Boot causes image size problems on some platforms.
Introduce CONFIG_BUG_CHECKS to switch this feature. It is enabled by default since it is the current behavior. Disable it if your platform needs to save memory footprint.
Suggested-by: Tom Rini trini@konsulko.com Signed-off-by: Masahiro Yamada yamada.masahiro@socionext.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v3: - Flip the default to 'y' - Rename CONFIG_ENABLE_BUG_CHECKS to CONFIG_BUG_CHECKS because I thought "ENABLE" was not a necessary word - define to "do {} while (0)"
Changes in v2: - Newly added
include/linux/bug.h | 9 ++++++++- lib/Kconfig | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/include/linux/bug.h b/include/linux/bug.h index f07bb71..045e639 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -6,17 +6,24 @@ #include <linux/compiler.h> #include <linux/printk.h>
+#ifdef CONFIG_BUG_CHECKS #define BUG() do { \ printk("BUG at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ panic("BUG!"); \ } while (0) +#define __WARN() \ + printk("WARNING at %s:%d/%s()!\n", __FILE__, __LINE__, __func__) +#else +#define BUG() do {} while (0) +#define __WARN() do {} while (0) +#endif
#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__); \ + __WARN(); \ unlikely(__ret_warn_on); \ })
diff --git a/lib/Kconfig b/lib/Kconfig index 00ac650..dee5dc2 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -45,6 +45,15 @@ config USE_TINY_PRINTF
The supported format specifiers are %c, %s, %u/%d and %x.
+config BUG_CHECKS + bool "Enable BUG/BUG_ON() checks and WARN_ON() logs" + default y + help + BUG(), BUG_ON(), and WARN_ON() print noisy messages. BUG() and + BUG_ON() also reboot or halt the system. + + Disable this if your platform needs to save memory footprint. + config PANIC_HANG bool "Do not reset the system on fatal error" help