git: 0777b000f111 - main - linuxkpi: Define `dev_WARN()` and `dev_WARN_ONCE()`

From: Jean-Sébastien Pédron <dumbbell_at_FreeBSD.org>
Date: Mon, 20 Mar 2023 20:47:45 UTC
The branch main has been updated by dumbbell:

URL: https://cgit.FreeBSD.org/src/commit/?id=0777b000f1118af4abd7adf18bcff358fe8afd5e

commit 0777b000f1118af4abd7adf18bcff358fe8afd5e
Author:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
AuthorDate: 2023-02-20 20:42:22 +0000
Commit:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
CommitDate: 2023-03-20 20:47:28 +0000

    linuxkpi: Define `dev_WARN()` and `dev_WARN_ONCE()`
    
    Reviewed by:    manu
    Approved by:    manu
    Differential Revision:  https://reviews.freebsd.org/D39049
---
 sys/compat/linuxkpi/common/include/linux/device.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/device.h b/sys/compat/linuxkpi/common/include/linux/device.h
index 18f2eef895c0..09a61bdd0a64 100644
--- a/sys/compat/linuxkpi/common/include/linux/device.h
+++ b/sys/compat/linuxkpi/common/include/linux/device.h
@@ -199,6 +199,20 @@ show_class_attr_string(struct class *class,
 #define	dev_printk(lvl, dev, fmt, ...)					\
 	    device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
 
+#define	dev_WARN(dev, fmt, ...)	\
+    device_printf((dev)->bsddev, "%s:%d: " fmt, __func__, __LINE__, ##__VA_ARGS__)
+
+#define	dev_WARN_ONCE(dev, condition, fmt, ...) do {		\
+	static bool __dev_WARN_ONCE;				\
+	bool __ret_warn_on = (condition);			\
+	if (unlikely(__ret_warn_on)) {				\
+		if (!__dev_WARN_ONCE) {				\
+			__dev_WARN_ONCE = true;			\
+			device_printf((dev)->bsddev, "%s:%d: " fmt, __func__, __LINE__, ##__VA_ARGS__); \
+		}						\
+	}							\
+} while (0)
+
 #define dev_info_once(dev, ...) do {		\
 	static bool __dev_info_once;		\
 	if (!__dev_info_once) {			\