device: Add dev_<level>_once variants
authorJoe Perches <joe@perches.com>
Tue, 18 Nov 2014 02:18:22 +0000 (18:18 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Nov 2014 03:40:11 +0000 (19:40 -0800)
Add the equivalents to pr_<level>_once.

Suggested-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/device.h

index ce1f21608b168f9b1f1759f5f4eefd4c4d4beae5..99fb07cb4f0694b599435d55da2c93bb258d4f2d 100644 (file)
@@ -1118,6 +1118,41 @@ do {                                                  \
 })
 #endif
 
+#ifdef CONFIG_PRINTK
+#define dev_level_once(dev_level, dev, fmt, ...)                       \
+do {                                                                   \
+       static bool __print_once __read_mostly;                         \
+                                                                       \
+       if (!__print_once) {                                            \
+               __print_once = true;                                    \
+               dev_level(dev, fmt, ##__VA_ARGS__);                     \
+       }                                                               \
+} while (0)
+#else
+#define dev_level_once(dev_level, dev, fmt, ...)                       \
+do {                                                                   \
+       if (0)                                                          \
+               dev_level(dev, fmt, ##__VA_ARGS__);                     \
+} while (0)
+#endif
+
+#define dev_emerg_once(dev, fmt, ...)                                  \
+       dev_level_once(dev_emerg, dev, fmt, ##__VA_ARGS__)
+#define dev_alert_once(dev, fmt, ...)                                  \
+       dev_level_once(dev_alert, dev, fmt, ##__VA_ARGS__)
+#define dev_crit_once(dev, fmt, ...)                                   \
+       dev_level_once(dev_crit, dev, fmt, ##__VA_ARGS__)
+#define dev_err_once(dev, fmt, ...)                                    \
+       dev_level_once(dev_err, dev, fmt, ##__VA_ARGS__)
+#define dev_warn_once(dev, fmt, ...)                                   \
+       dev_level_once(dev_warn, dev, fmt, ##__VA_ARGS__)
+#define dev_notice_once(dev, fmt, ...)                                 \
+       dev_level_once(dev_notice, dev, fmt, ##__VA_ARGS__)
+#define dev_info_once(dev, fmt, ...)                                   \
+       dev_level_once(dev_info, dev, fmt, ##__VA_ARGS__)
+#define dev_dbg_once(dev, fmt, ...)                                    \
+       dev_level_once(dev_info, dev, fmt, ##__VA_ARGS__)
+
 #define dev_level_ratelimited(dev_level, dev, fmt, ...)                        \
 do {                                                                   \
        static DEFINE_RATELIMIT_STATE(_rs,                              \