Skip to content

Commit 1fc0ca9

Browse files
jognesspmladek
authored andcommitted
printk: add con_printk() macro for console details
It is useful to generate log messages that include details about the related console. Rather than duplicate the code to assemble the details, put that code into a macro con_printk(). Once console printers become threaded, this macro will find more users. Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 1f47e8a commit 1fc0ca9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

kernel/printk/printk.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,6 +3015,11 @@ static void try_enable_default_console(struct console *newcon)
30153015
newcon->flags |= CON_CONSDEV;
30163016
}
30173017

3018+
#define con_printk(lvl, con, fmt, ...) \
3019+
printk(lvl pr_fmt("%sconsole [%s%d] " fmt), \
3020+
(con->flags & CON_BOOT) ? "boot" : "", \
3021+
con->name, con->index, ##__VA_ARGS__)
3022+
30183023
/*
30193024
* The console driver calls this routine during kernel initialization
30203025
* to register the console printing procedure with printk() and to
@@ -3153,9 +3158,7 @@ void register_console(struct console *newcon)
31533158
* users know there might be something in the kernel's log buffer that
31543159
* went to the bootconsole (that they do not see on the real console)
31553160
*/
3156-
pr_info("%sconsole [%s%d] enabled\n",
3157-
(newcon->flags & CON_BOOT) ? "boot" : "" ,
3158-
newcon->name, newcon->index);
3161+
con_printk(KERN_INFO, newcon, "enabled\n");
31593162
if (bootcon_enabled &&
31603163
((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) &&
31613164
!keep_bootcon) {
@@ -3174,9 +3177,7 @@ int unregister_console(struct console *console)
31743177
struct console *con;
31753178
int res;
31763179

3177-
pr_info("%sconsole [%s%d] disabled\n",
3178-
(console->flags & CON_BOOT) ? "boot" : "" ,
3179-
console->name, console->index);
3180+
con_printk(KERN_INFO, console, "disabled\n");
31803181

31813182
res = _braille_unregister_console(console);
31823183
if (res < 0)

0 commit comments

Comments
 (0)