printk: Make the printk*once() variants return a value
authorBorislav Petkov <bp@suse.de>
Mon, 4 Jul 2016 22:31:26 +0000 (00:31 +0200)
committerIngo Molnar <mingo@kernel.org>
Fri, 8 Jul 2016 09:33:18 +0000 (11:33 +0200)
Have printk*once() return a bool which denotes whether the string was
printed or not so that calling code can react accordingly.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1467671487-10344-3-git-send-email-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
include/linux/printk.h

index f4da695..f136b22 100644 (file)
@@ -108,11 +108,14 @@ struct va_format {
  * Dummy printk for disabled debugging statements to use whilst maintaining
  * gcc's format checking.
  */
-#define no_printk(fmt, ...)                    \
-do {                                           \
-       if (0)                                  \
-               printk(fmt, ##__VA_ARGS__);     \
-} while (0)
+#define no_printk(fmt, ...)                            \
+({                                                     \
+       do {                                            \
+               if (0)                                  \
+                       printk(fmt, ##__VA_ARGS__);     \
+       } while (0);                                    \
+       0;                                              \
+})
 
 #ifdef CONFIG_EARLY_PRINTK
 extern asmlinkage __printf(1, 2)
@@ -309,20 +312,24 @@ extern asmlinkage void dump_stack(void) __cold;
 #define printk_once(fmt, ...)                                  \
 ({                                                             \
        static bool __print_once __read_mostly;                 \
+       bool __ret_print_once = !__print_once;                  \
                                                                \
        if (!__print_once) {                                    \
                __print_once = true;                            \
                printk(fmt, ##__VA_ARGS__);                     \
        }                                                       \
+       unlikely(__ret_print_once);                             \
 })
 #define printk_deferred_once(fmt, ...)                         \
 ({                                                             \
        static bool __print_once __read_mostly;                 \
+       bool __ret_print_once = !__print_once;                  \
                                                                \
        if (!__print_once) {                                    \
                __print_once = true;                            \
                printk_deferred(fmt, ##__VA_ARGS__);            \
        }                                                       \
+       unlikely(__ret_print_once);                             \
 })
 #else
 #define printk_once(fmt, ...)                                  \