[PATCH master v2 1/3] include: linux/printk: implement pr_*_once macros
Sascha Hauer
sha at pengutronix.de
Thu Feb 2 23:58:58 PST 2023
On Thu, Feb 02, 2023 at 02:34:13PM +0100, Ahmad Fatoum wrote:
> 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 at pengutronix.de>
> ---
> v1 -> v2:
> unchanged
> ---
> include/linux/printk.h | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
Applied, thanks
Sascha
>
> 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
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list