[PATCH 14/18] include: implement dev_warn_once and friends

Sascha Hauer sha at pengutronix.de
Mon Nov 13 04:38:38 PST 2023


On Fri, Nov 10, 2023 at 10:44:17PM +0100, Ahmad Fatoum wrote:
> We already have pr_once, so duplicate it for dev_warn and friends as
> well.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  drivers/firmware/arm_scmi/driver.c |  4 ++--
>  include/linux/printk.h             | 29 ++++++++++++++++++++++++++++-
>  2 files changed, 30 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> index c3536d6e9fbd..98f672746527 100644
> --- a/drivers/firmware/arm_scmi/driver.c
> +++ b/drivers/firmware/arm_scmi/driver.c
> @@ -988,7 +988,7 @@ static void scmi_create_protocol_devices(struct device_node *np,
>   */
>  int scmi_protocol_device_request(const struct scmi_device_id *id_table)
>  {
> -	int ret = 0;
> +	int id, ret = 0;
>  	struct list_head *phead = NULL;
>  	struct scmi_requested_dev *rdev;
>  	struct scmi_info *info;
> @@ -1001,7 +1001,7 @@ int scmi_protocol_device_request(const struct scmi_device_id *id_table)
>  	 * Search for the matching protocol rdev list and then search
>  	 * of any existent equally named device...fails if any duplicate found.
>  	 */
> -	idr_for_each_entry(&scmi_requested_devices, idr) {
> +	idr_for_each_entry(&scmi_requested_devices, idr, id) {
>  		struct list_head *head = idr->ptr;
>  		if (!phead) {
>  			/* A list found registered in the IDR is never empty */

These changes should be part of an earlier patch, right?

Sascha

> diff --git a/include/linux/printk.h b/include/linux/printk.h
> index cd4c3cb68edb..0e9604bbe967 100644
> --- a/include/linux/printk.h
> +++ b/include/linux/printk.h
> @@ -57,7 +57,15 @@ static inline int pr_print(int level, const char *format, ...)
>  		(level) <= LOGLEVEL ? dev_printf((level), (dev), (format), ##args) : 0; \
>  	 })
>  
> -
> +#define __dev_printf_once(level, dev, format, args...) do {	\
> +	static bool __print_once;				\
> +								\
> +	if (!__print_once && (level) <= LOGLEVEL) {		\
> +		__print_once = true;				\
> +		dev_printf((level), (dev), (format), ##args);	\
> +	}							\
> +} while (0)
> + 
>  #define dev_emerg(dev, format, arg...)		\
>  	__dev_printf(0, (dev) , format , ## arg)
>  #define dev_alert(dev, format, arg...)		\
> @@ -77,6 +85,25 @@ static inline int pr_print(int level, const char *format, ...)
>  #define dev_vdbg(dev, format, arg...)		\
>  	__dev_printf(8, (dev) , format , ## arg)
>  
> +#define dev_emerg_once(dev, format, arg...)		\
> +	__dev_printf_once(0, (dev) , format , ## arg)
> +#define dev_alert_once(dev, format, arg...)		\
> +	__dev_printf_once(1, (dev) , format , ## arg)
> +#define dev_crit_once(dev, format, arg...)		\
> +	__dev_printf_once(2, (dev) , format , ## arg)
> +#define dev_err_once(dev, format, arg...)		\
> +	__dev_prin_oncetf(3, (dev) , format , ## arg)
> +#define dev_warn_once(dev, format, arg...)		\
> +	__dev_printf_once(4, (dev) , format , ## arg)
> +#define dev_notice_once(dev, format, arg...)		\
> +	__dev_printf(_once5, (dev) , format , ## arg)
> +#define dev_info_once(dev, format, arg...)		\
> +	__dev_printf_once(6, (dev) , format , ## arg)
> +#define dev_dbg_once(dev, format, arg...)		\
> +	__dev_prin_oncetf(7, (dev) , format , ## arg)
> +#define dev_vdbg_once(dev, format, arg...)		\
> +	__dev_printf_once(8, (dev) , format , ## arg)
> +
>  #if LOGLEVEL >= MSG_ERR
>  int dev_err_probe(struct device *dev, int err, const char *fmt, ...)
>  	__attribute__ ((format(__printf__, 3, 4)));
> -- 
> 2.39.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