From: "Lothar Waßmann" <LW@KARO-electronics.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 3/5] Introduce CONFIG_ENABLE_BUG_CHECKS to disable BUG{_ON} by default
Date: Tue, 12 Dec 2017 10:06:19 +0100 [thread overview]
Message-ID: <20171212100619.16579688@karo-electronics.de> (raw)
In-Reply-To: <1512358624-6309-4-git-send-email-yamada.masahiro@socionext.com>
Hi,
On Mon, 4 Dec 2017 12:37:02 +0900 Masahiro Yamada wrote:
> BUG() and BUG_ON() are generally used to test a condition that should
> never happen. If it does, it is a bug.
>
> Linux always enables them, but doing so in U-Boot causes image size
> problems on some platforms. Introduce CONFIG_ENABLE_BUG_CHECKS to
> make them no-op by default. Platforms without image size constraint
> are free to enable this option to catch bugs easily.
>
> Likewise, silence WARN_ON() unless this option is enabled.
>
> Suggested-by: Tom Rini <trini@konsulko.com>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
>
> Changes in v2:
> - Newly added
>
> include/linux/bug.h | 9 ++++++++-
> lib/Kconfig | 7 +++++++
> 2 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/bug.h b/include/linux/bug.h
> index f07bb71..ac1c7de 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_ENABLE_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()
> +#define __WARN()
> +#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..36b1b3b 100644
> --- a/lib/Kconfig
> +++ b/lib/Kconfig
> @@ -45,6 +45,13 @@ config USE_TINY_PRINTF
>
> The supported format specifiers are %c, %s, %u/%d and %x.
>
> +config ENABLE_BUG_CHECKS
> + bool "Enable BUG/BUG_ON() checks and WARN_ON() logs"
> + help
This should be 'default y' IMO to keep the current behaviour for all
existing platforms.
Lothar Waßmann
next prev parent reply other threads:[~2017-12-12 9:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-04 3:36 [U-Boot] [PATCH v2 0/5] Remove assert() Masahiro Yamada
2017-12-04 3:37 ` [U-Boot] [PATCH v2 1/5] Move CONFIG_PANIC_HANG to Kconfig Masahiro Yamada
2017-12-04 16:55 ` York Sun
2017-12-30 1:19 ` [U-Boot] [U-Boot,v2,1/5] " Tom Rini
2017-12-04 3:37 ` [U-Boot] [PATCH v2 2/5] Enable CONFIG_PANIC_HANG for boards without do_reset() Masahiro Yamada
2017-12-12 4:38 ` Simon Glass
2017-12-04 3:37 ` [U-Boot] [PATCH v2 3/5] Introduce CONFIG_ENABLE_BUG_CHECKS to disable BUG{_ON} by default Masahiro Yamada
2017-12-12 4:38 ` Simon Glass
2017-12-12 9:06 ` Lothar Waßmann [this message]
2017-12-12 13:47 ` Tom Rini
2017-12-14 21:35 ` Masahiro Yamada
2017-12-04 3:37 ` [U-Boot] [PATCH v2 4/5] treewide: convert assert() to BUG_ON() Masahiro Yamada
2017-12-04 3:37 ` [U-Boot] [PATCH v2 5/5] Remove assert() Masahiro Yamada
2017-12-12 4:38 ` Simon Glass
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=20171212100619.16579688@karo-electronics.de \
--to=lw@karo-electronics.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).