Commit 2c6b4b70 authored by John Ogness's avatar John Ogness Committed by Petr Mladek

netconsole: avoid CON_ENABLED misuse to track registration

The CON_ENABLED flag is being misused to track whether or not the
extended console should be or has been registered. Instead use
a local variable to decide if the extended console should be
registered and console_is_registered() to determine if it has
been registered.

Also add a check in cleanup_netconsole() to only unregister the
extended console if it has been registered.
Signed-off-by: default avatarJohn Ogness <john.ogness@linutronix.de>
Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20221116162152.193147-32-john.ogness@linutronix.de
parent 9490b22a
...@@ -332,10 +332,8 @@ static ssize_t enabled_store(struct config_item *item, ...@@ -332,10 +332,8 @@ static ssize_t enabled_store(struct config_item *item,
} }
if (enabled) { /* true */ if (enabled) { /* true */
if (nt->extended && !(netconsole_ext.flags & CON_ENABLED)) { if (nt->extended && !console_is_registered(&netconsole_ext))
netconsole_ext.flags |= CON_ENABLED;
register_console(&netconsole_ext); register_console(&netconsole_ext);
}
/* /*
* Skip netpoll_parse_options() -- all the attributes are * Skip netpoll_parse_options() -- all the attributes are
...@@ -869,7 +867,7 @@ static void write_msg(struct console *con, const char *msg, unsigned int len) ...@@ -869,7 +867,7 @@ static void write_msg(struct console *con, const char *msg, unsigned int len)
static struct console netconsole_ext = { static struct console netconsole_ext = {
.name = "netcon_ext", .name = "netcon_ext",
.flags = CON_EXTENDED, /* starts disabled, registered on first use */ .flags = CON_ENABLED | CON_EXTENDED,
.write = write_ext_msg, .write = write_ext_msg,
}; };
...@@ -883,6 +881,7 @@ static int __init init_netconsole(void) ...@@ -883,6 +881,7 @@ static int __init init_netconsole(void)
{ {
int err; int err;
struct netconsole_target *nt, *tmp; struct netconsole_target *nt, *tmp;
bool extended = false;
unsigned long flags; unsigned long flags;
char *target_config; char *target_config;
char *input = config; char *input = config;
...@@ -895,11 +894,12 @@ static int __init init_netconsole(void) ...@@ -895,11 +894,12 @@ static int __init init_netconsole(void)
goto fail; goto fail;
} }
/* Dump existing printks when we register */ /* Dump existing printks when we register */
if (nt->extended) if (nt->extended) {
netconsole_ext.flags |= CON_PRINTBUFFER | extended = true;
CON_ENABLED; netconsole_ext.flags |= CON_PRINTBUFFER;
else } else {
netconsole.flags |= CON_PRINTBUFFER; netconsole.flags |= CON_PRINTBUFFER;
}
spin_lock_irqsave(&target_list_lock, flags); spin_lock_irqsave(&target_list_lock, flags);
list_add(&nt->list, &target_list); list_add(&nt->list, &target_list);
...@@ -915,7 +915,7 @@ static int __init init_netconsole(void) ...@@ -915,7 +915,7 @@ static int __init init_netconsole(void)
if (err) if (err)
goto undonotifier; goto undonotifier;
if (netconsole_ext.flags & CON_ENABLED) if (extended)
register_console(&netconsole_ext); register_console(&netconsole_ext);
register_console(&netconsole); register_console(&netconsole);
pr_info("network logging started\n"); pr_info("network logging started\n");
...@@ -945,6 +945,7 @@ static void __exit cleanup_netconsole(void) ...@@ -945,6 +945,7 @@ static void __exit cleanup_netconsole(void)
{ {
struct netconsole_target *nt, *tmp; struct netconsole_target *nt, *tmp;
if (console_is_registered(&netconsole_ext))
unregister_console(&netconsole_ext); unregister_console(&netconsole_ext);
unregister_console(&netconsole); unregister_console(&netconsole);
dynamic_netconsole_exit(); dynamic_netconsole_exit();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment