Skip to content

Commit 069f0cd

Browse files
suryasaimadhuIngo Molnar
authored andcommitted
printk: Make the printk*once() variants return a value
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 <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent ef16dd0 commit 069f0cd

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

include/linux/printk.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,14 @@ struct va_format {
108108
* Dummy printk for disabled debugging statements to use whilst maintaining
109109
* gcc's format checking.
110110
*/
111-
#define no_printk(fmt, ...) \
112-
do { \
113-
if (0) \
114-
printk(fmt, ##__VA_ARGS__); \
115-
} while (0)
111+
#define no_printk(fmt, ...) \
112+
({ \
113+
do { \
114+
if (0) \
115+
printk(fmt, ##__VA_ARGS__); \
116+
} while (0); \
117+
0; \
118+
})
116119

117120
#ifdef CONFIG_EARLY_PRINTK
118121
extern asmlinkage __printf(1, 2)
@@ -309,20 +312,24 @@ extern asmlinkage void dump_stack(void) __cold;
309312
#define printk_once(fmt, ...) \
310313
({ \
311314
static bool __print_once __read_mostly; \
315+
bool __ret_print_once = !__print_once; \
312316
\
313317
if (!__print_once) { \
314318
__print_once = true; \
315319
printk(fmt, ##__VA_ARGS__); \
316320
} \
321+
unlikely(__ret_print_once); \
317322
})
318323
#define printk_deferred_once(fmt, ...) \
319324
({ \
320325
static bool __print_once __read_mostly; \
326+
bool __ret_print_once = !__print_once; \
321327
\
322328
if (!__print_once) { \
323329
__print_once = true; \
324330
printk_deferred(fmt, ##__VA_ARGS__); \
325331
} \
332+
unlikely(__ret_print_once); \
326333
})
327334
#else
328335
#define printk_once(fmt, ...) \

0 commit comments

Comments
 (0)