summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-02-02 14:34:13 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2023-02-03 08:59:46 +0100
commit094f26c6f4848d141325a80a933dfef4e63adcf9 (patch)
tree8f067451a8ebaece641097c720ce73da3806fe4b
parentd86bbaed71cf8928575b40e4bfa904cded5fa2d2 (diff)
downloadbarebox-094f26c6f4848d141325a80a933dfef4e63adcf9.tar.gz
barebox-094f26c6f4848d141325a80a933dfef4e63adcf9.tar.xz
include: linux/printk: implement pr_*_once macros
These are useful as a less verbose alternative to WARN_ONCE, which also prints a stack trace if possible. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230202133415.319020-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--include/linux/printk.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/include/linux/printk.h b/include/linux/printk.h
index 2fd6551e0c..a9d1b05f6f 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -94,6 +94,15 @@ static inline int dev_err_probe(struct device *dev, int err, const char *fmt,
(level) <= LOGLEVEL ? pr_print((level), (format), ##args) : 0; \
})
+#define __pr_printk_once(level, format, args...) do { \
+ static bool __print_once; \
+ \
+ if (!__print_once && (level) <= LOGLEVEL) { \
+ __print_once = true; \
+ pr_print((level), (format), ##args); \
+ } \
+} while (0)
+
#ifndef pr_fmt
#define pr_fmt(fmt) fmt
#endif
@@ -110,7 +119,18 @@ static inline int dev_err_probe(struct device *dev, int err, const char *fmt,
#define pr_vdebug(fmt, arg...) __pr_printk(8, pr_fmt(fmt), ##arg)
#define pr_cont(fmt, arg...) __pr_printk(-1, fmt, ##arg)
+#define pr_emerg_once(fmt, arg...) __pr_printk_once(0, pr_fmt(fmt), ##arg)
+#define pr_alert_once(fmt, arg...) __pr_printk_once(1, pr_fmt(fmt), ##arg)
+#define pr_crit_once(fmt, arg...) __pr_printk_once(2, pr_fmt(fmt), ##arg)
+#define pr_err_once(fmt, arg...) __pr_printk_once(3, pr_fmt(fmt), ##arg)
+#define pr_warning_once(fmt, arg...) __pr_printk_once(4, pr_fmt(fmt), ##arg)
+#define pr_notice_once(fmt, arg...) __pr_printk_once(5, pr_fmt(fmt), ##arg)
+#define pr_info_once(fmt, arg...) __pr_printk_once(6, pr_fmt(fmt), ##arg)
+#define pr_debug_once(fmt, arg...) __pr_printk_once(7, pr_fmt(fmt), ##arg)
+#define pr_vdebug_once(fmt, arg...) __pr_printk_once(8, pr_fmt(fmt), ##arg)
+
#define pr_warn pr_warning
+#define pr_warn_once pr_warning_once
int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size,
int swab);