From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jmBhT-0001vC-Uq for barebox@lists.infradead.org; Fri, 19 Jun 2020 07:44:36 +0000 From: Sascha Hauer Date: Fri, 19 Jun 2020 09:44:25 +0200 Message-Id: <20200619074427.17289-20-s.hauer@pengutronix.de> In-Reply-To: <20200619074427.17289-1-s.hauer@pengutronix.de> References: <20200619074427.17289-1-s.hauer@pengutronix.de> MIME-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH 19/21] Add WARN_ONCE() macro To: Barebox List Cc: =?UTF-8?q?Daniel=20Gl=C3=B6ckner?= This adds WARN_ONCE from the Linux Kernel. It is useful to warn only once when we would otherwise spam the log. Signed-off-by: Sascha Hauer --- include/asm-generic/bug.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h index 8583d2425f..82b78261fc 100644 --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -34,4 +34,17 @@ unlikely(__ret_warn_on); \ }) #endif + +#define WARN_ONCE(condition, format...) ({ \ + static int __warned; \ + int __ret_warn_once = !!(condition); \ + \ + if (unlikely(__ret_warn_once)) { \ + if (WARN(!__warned, format)) { \ + __warned = 1; \ + dump_stack(); \ + } \ + } \ + unlikely(__ret_warn_once); \ +}) #endif -- 2.27.0 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox