From 948f32c8563568a76153f61ee4094c5aafe21eaf Mon Sep 17 00:00:00 2001 From: Ramon Fried Date: Wed, 6 Jun 2018 00:38:59 +0300 Subject: [PATCH] bug.h: introduce WARN_ONCE Add WARN_ONCE definition to allow single time notification of warnings to the user. Taken from Linux kernel (4.17) with slight changes (Removed __section(.data.once)) Signed-off-by: Ramon Fried [trini: Drop the musb and dwc3 compat versions] Signed-off-by: Tom Rini --- drivers/usb/dwc3/linux-compat.h | 1 - drivers/usb/musb-new/linux-compat.h | 6 ------ include/linux/bug.h | 18 ++++++++++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/usb/dwc3/linux-compat.h b/drivers/usb/dwc3/linux-compat.h index 35850f91a3..82793765be 100644 --- a/drivers/usb/dwc3/linux-compat.h +++ b/drivers/usb/dwc3/linux-compat.h @@ -11,7 +11,6 @@ #ifndef __DWC3_LINUX_COMPAT__ #define __DWC3_LINUX_COMPAT__ -#define WARN(val, format, arg...) debug(format, ##arg) #define dev_WARN(dev, format, arg...) debug(format, ##arg) static inline size_t strlcat(char *dest, const char *src, size_t n) diff --git a/drivers/usb/musb-new/linux-compat.h b/drivers/usb/musb-new/linux-compat.h index 7bb53d2b19..f366ae58e8 100644 --- a/drivers/usb/musb-new/linux-compat.h +++ b/drivers/usb/musb-new/linux-compat.h @@ -5,12 +5,6 @@ #include #include -#define WARN(condition, fmt, args...) ({ \ - int ret_warn = !!condition; \ - if (ret_warn) \ - printf(fmt, ##args); \ - ret_warn; }) - #define device_init_wakeup(dev, a) do {} while (0) #define platform_data device_data diff --git a/include/linux/bug.h b/include/linux/bug.h index f07bb716fc..29f84168a3 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -20,6 +20,13 @@ unlikely(__ret_warn_on); \ }) +#define WARN(condition, format...) ({ \ + int __ret_warn_on = !!(condition); \ + if (unlikely(__ret_warn_on)) \ + printf(format); \ + unlikely(__ret_warn_on); \ +}) + #define WARN_ON_ONCE(condition) ({ \ static bool __warned; \ int __ret_warn_once = !!(condition); \ @@ -31,4 +38,15 @@ unlikely(__ret_warn_once); \ }) +#define WARN_ONCE(condition, format...) ({ \ + static bool __warned; \ + int __ret_warn_once = !!(condition); \ + \ + if (unlikely(__ret_warn_once && !__warned)) { \ + __warned = true; \ + WARN(1, format); \ + } \ + unlikely(__ret_warn_once); \ +}) + #endif /* _LINUX_BUG_H */ -- 2.25.1