From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 1/3] include: linux/printk: implement pr_*_once macros
Date: Thu, 2 Feb 2023 13:57:36 +0100 [thread overview]
Message-ID: <20230202125738.233147-1-a.fatoum@pengutronix.de> (raw)
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>
---
include/linux/printk.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/include/linux/printk.h b/include/linux/printk.h
index 2fd6551e0ccb..a9d1b05f6f0f 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);
--
2.30.2
next reply other threads:[~2023-02-02 12:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-02 12:57 Ahmad Fatoum [this message]
2023-02-02 12:57 ` [PATCH master 2/3] fs: tftp: print message when NIC can't keep us with TFTP windowsize Ahmad Fatoum
2023-02-02 12:57 ` [PATCH 3/3] include: printk: retire printk_once for pr_debug_once Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230202125738.233147-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox