From patchwork Wed Sep 13 11:45:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 813400 X-Patchwork-Delegate: yamada.m@jp.panasonic.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="ZLChMqyH"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xsg0y549Fz9s7g for ; Wed, 13 Sep 2017 21:48:50 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 56609C220AA; Wed, 13 Sep 2017 11:47:02 +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 F175DC22606; Wed, 13 Sep 2017 11:45:45 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 02A1BC220CB; Wed, 13 Sep 2017 11:45:32 +0000 (UTC) Received: from conuserg-10.nifty.com (conuserg-10.nifty.com [210.131.2.77]) by lists.denx.de (Postfix) with ESMTPS id EAE8FC22521 for ; Wed, 13 Sep 2017 11:45:31 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id v8DBjE4t018351; Wed, 13 Sep 2017 20:45:20 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com v8DBjE4t018351 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1505303121; bh=+sRqIcFE+69+EyVw9ph5oCFjxICzh6Xbafzl0a7O/z4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZLChMqyHh6OprVkbOy9afLq0scuxtRTZ5fKM/7WgV/nUkaWihbkpIxabH3+4mAfWF bDXQDFwF5hFxyzLxmhEF+Ds9p2Sx/Z+dA/X+KZmuquhiV8YEXXitgLjHRBV6FXxU1+ desfr4Q+PvCm8/pmxn5UGom/JCdiJcQ82JlIrRujks4C8WX/kWrfJD5mlXswwky4Bx zkGq4YTSS76jg1jhP/8Mom++drzl9WsM2M5FaCmhkJQiy2c9bAB3jNQ2KIr4D9TtgF kB6uc1Q91qAbeSXuLP57/z5+R47qNg6Dkp1A/U6Be/agGIHOZdNu/HZtirPFYwAdSY OUO6AoON4B0Zg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Wed, 13 Sep 2017 20:45:06 +0900 Message-Id: <1505303106-9780-7-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505303106-9780-1-git-send-email-yamada.masahiro@socionext.com> References: <1505303106-9780-1-git-send-email-yamada.masahiro@socionext.com> Cc: Marek Vasut Subject: [U-Boot] [PATCH 6/6] bug.h: move runtime BUG/WARN macros into 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" and define BUG(_ON) in a different way. To avoid the conflict, they wrap the defines with #ifndef BUG, enabling the first-included one. Horrible. Collect them into a self-contained header to make these macros easier to use. Signed-off-by: Masahiro Yamada --- 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 64db4ec..5cbe377 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 e66b8ff..f5344a0 100644 --- a/include/common.h +++ b/include/common.h @@ -23,6 +23,7 @@ typedef volatile unsigned char vu_char; #include #include #include +#include #include #include #include @@ -89,14 +90,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 /* boot information for Linux kernel */ diff --git a/include/linux/bug.h b/include/linux/bug.h index 133544c..f07bb71 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -1,6 +1,34 @@ #ifndef _LINUX_BUG_H #define _LINUX_BUG_H +#include /* for panic() */ #include +#include +#include + +#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 bc027ad..1b3f089 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 at %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 */