From patchwork Mon Dec 4 03:37:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 844070 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nifty.com header.i=@nifty.com header.b="g3dU2ize"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yqrDy6sJqz9s1h for ; Mon, 4 Dec 2017 14:38:10 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id B5D87C21FA6; Mon, 4 Dec 2017 03:38:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 1BC9FC21FA6; Mon, 4 Dec 2017 03:38:01 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4ECF2C22017; Mon, 4 Dec 2017 03:37:59 +0000 (UTC) Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lists.denx.de (Postfix) with ESMTPS id 679C1C21FA6 for ; Mon, 4 Dec 2017 03:37:58 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id vB43bE4r022247; Mon, 4 Dec 2017 12:37:19 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com vB43bE4r022247 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1512358639; bh=Gi/ht9c3fyn/8Akvk6mMZQPpPxMdcH+IhacxlC4Sspg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g3dU2izeC7EujLUktrf99jF56OzacXVICNvbiJ1sbKayd7lmz8dHJMtP/l9YV2/Cm aeNpBRmRXAh3GThefI1gL06yVcEgi+NgLbS09oTFbplWZ72YdFjdNWNNxd5UcH4isv T4kw7XF9Wbriv2FFJzOmR6CWjwaRPeqMtZ9FB9VyRpGoTJztn8lGu3A9r1pHETHb8+ aUlOZxuML29qzGDfVqvpFPloRLcKmaCK4GQ08AxWuhg7vi9Lm4VQslmoTr3Jj9RSwT DOmSW6tCzQGMMVSwN3Cdf0CsZbVHZHQdQWvE0wgP4QS13Lb3TNrwyeC/tFC8K3IMlB PizUmc8XOO6XQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Mon, 4 Dec 2017 12:37:02 +0900 Message-Id: <1512358624-6309-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1512358624-6309-1-git-send-email-yamada.masahiro@socionext.com> References: <1512358624-6309-1-git-send-email-yamada.masahiro@socionext.com> Cc: Marek Vasut , Tom Rini Subject: [U-Boot] [PATCH v2 3/5] Introduce CONFIG_ENABLE_BUG_CHECKS to disable BUG{_ON} by default X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 Signed-off-by: Masahiro Yamada Reviewed-by: Simon Glass --- 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 #include +#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 + BUG() and BUG_ON() are no-op by default. This option enables + them to print noisy messages, then reboot or halt the system. + It also enables WARN_ON() messages. + config PANIC_HANG bool "Do not reset the system on fatal error" help