From patchwork Wed Jan 10 01:45:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 123994 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4701483qgn; Tue, 9 Jan 2018 17:48:46 -0800 (PST) X-Google-Smtp-Source: ACJfBouVJRhnI1YeXgior536gVtDmc4Q2lOvvcPLKuNJQcEEWwwN1KXk0J33/h4lL6iJNQbiv3BG X-Received: by 10.80.230.8 with SMTP id y8mr23496784edm.203.1515548926022; Tue, 09 Jan 2018 17:48:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515548926; cv=none; d=google.com; s=arc-20160816; b=b5af53hqAU/xcaZerWlIrkzbnmFVIqc10oFq8U98efQ3/Fin3IwsXMRQe0arcyXo70 T2HpkyvK9DhdYnWLmK4nbMNiMFiTYimWMZ1DPj7Z1AEQJAdwUe50gtNeklYrvpg72Iyo RdTxeHC8Uls4En2PE1Hs+rlZjDE5XEny7R2NdmNjPjQEoylMXb2PNO+mIPXkr7pGG+X0 FwtwB5Op+CAO84UgnKAgGF008adXMhxOntqL1/lI4wztpU5MtGdgp+AfHCn1/hnqDpTV vacXpe1zY+ogUdYwzStZs2F/+YLb9mvPJiO1aOrbBxzY3eprw4wqK0+sUcTnSXhH05QJ ByCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:dkim-filter:arc-authentication-results; bh=JR4Ct9dkecma1s4RUq8Wh9Wiw9cYumjDcrdJVs3QVMU=; b=F1jKEHl+ShuNleB1QZt9KPCC+e+BPrB3naNhKY3c19HGUs8qDe2F2LAEXwgaFK9x16 7J+oO9BJbQIyCN3GCRsnRuSb8HuylUZM1M8IhJyZi4nfoZVwvCTqWRBgEcHSSx/XlYVK DcaI7uPk9Z+ZNkNoQL7thUCLQ1WkyBBF+44IIp+TKtQSpBA6W5ugthrpt4QbxGIe7mwC tyZ1HbwRjmc4tYmSgYnvESXeFcrDEeZrWVgmIEYP2bBKNUlGcFIHQIc5kpBXXthxExZc bTMbjVMimpa2st68x1llBiGUwt4rNn5RMwr7U65omdzEf5AtO6J9Sk+7C2lv9MyfOX/V KHlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=SfzIgtCl; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id z17si3394495eda.152.2018.01.09.17.48.45; Tue, 09 Jan 2018 17:48:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=SfzIgtCl; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id A41AEC21C59; Wed, 10 Jan 2018 01:46:52 +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 6BE72C21F74; Wed, 10 Jan 2018 01:46:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A555AC21C29; Wed, 10 Jan 2018 01:45:56 +0000 (UTC) Received: from conuserg-11.nifty.com (conuserg-11.nifty.com [210.131.2.78]) by lists.denx.de (Postfix) with ESMTPS id 8180AC21C8F for ; Wed, 10 Jan 2018 01:45:55 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id w0A1jUkV021339; Wed, 10 Jan 2018 10:45:33 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com w0A1jUkV021339 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1515548734; bh=TVFEUHzZxLLmuXDtAD+zZhpBW9ZXuuW9h/WG/oGL83E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SfzIgtClpJu7ULrl3C9BFdwvRgi/RhmK1ZGl4G99ctJaloTnTmiVluJnFEb9+EnGz LMwtDanoRoiIKuu15pP6IG1T04wyD+63b0Sahpg3pU/U/IBab5XjAAbZRAOT5rieul XssnG3uNhSyFrBv7AtUIrNT8rmMtGChfTYbnvImWn2ApNVOHgG2msDTsoiqXZ3mNmd nKGhqjY1CJkzg8sD1J086lxITIsaxXw/saLnmq08cb0Q6q5YotVGUC7HuglNodEsxW F1iaBrivudiJVTzyqbFQP4h6tcplk622fcCz8NdfNNvBd8vGQWa6d7+qZMl9bGydK2 gftmjFZMeNgcQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Wed, 10 Jan 2018 10:45:21 +0900 Message-Id: <1515548724-31869-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515548724-31869-1-git-send-email-yamada.masahiro@socionext.com> References: <1515548724-31869-1-git-send-email-yamada.masahiro@socionext.com> Cc: Tom Rini Subject: [U-Boot] [PATCH v3 3/6] Introduce CONFIG_BUG_CHECKS to allow to disable BUG{_ON} and WARN_ON 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(), 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 Signed-off-by: Masahiro Yamada Reviewed-by: Simon Glass --- 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 #include +#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