From 11bb4944f014d756f35261f5afcb346901ef1efa Mon Sep 17 00:00:00 2001 From: Peter Zijlstra Date: Mon, 2 Jun 2025 15:08:30 +0200 Subject: [PATCH] x86/bug: Implement WARN_ONCE() Implement WARN_ONCE like WARN using BUGFLAG_ONCE. Signed-off-by: Peter Zijlstra (Intel) Link: https://patch.msgid.link/20251110115758.339309119@infradead.org --- arch/x86/include/asm/bug.h | 9 +++++++++ include/asm-generic/bug.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h index b5474603460b4..87199e6633f98 100644 --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -178,6 +178,15 @@ do { \ #define __WARN_printf(taint, fmt, arg...) \ __WARN_print_arg(BUGFLAG_TAINT(taint), fmt, ## arg) +#define WARN_ONCE(cond, format, arg...) ({ \ + int __ret_warn_on = !!(cond); \ + if (unlikely(__ret_warn_on)) { \ + __WARN_print_arg(BUGFLAG_ONCE|BUGFLAG_TAINT(TAINT_WARN),\ + format, ## arg); \ + } \ + __ret_warn_on; \ +}) + #endif /* HAVE_ARCH_BUG_FORMAT_ARGS */ #include diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h index e512071216bec..09e8eccee8ed9 100644 --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -180,8 +180,10 @@ extern __printf(1, 2) void __warn_printk(const char *fmt, ...); DO_ONCE_LITE_IF(condition, WARN_ON, 1) #endif +#ifndef WARN_ONCE #define WARN_ONCE(condition, format...) \ DO_ONCE_LITE_IF(condition, WARN, 1, format) +#endif #define WARN_TAINT_ONCE(condition, taint, format...) \ DO_ONCE_LITE_IF(condition, WARN_TAINT, 1, taint, format) -- 2.47.3