Skip to content

Commit 2c6b4b7

Browse files
jognesspmladek
authored andcommitted
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: 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 9490b22 commit 2c6b4b7

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

drivers/net/netconsole.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,8 @@ static ssize_t enabled_store(struct config_item *item,
332332
}
333333

334334
if (enabled) { /* true */
335-
if (nt->extended && !(netconsole_ext.flags & CON_ENABLED)) {
336-
netconsole_ext.flags |= CON_ENABLED;
335+
if (nt->extended && !console_is_registered(&netconsole_ext))
337336
register_console(&netconsole_ext);
338-
}
339337

340338
/*
341339
* 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)
869867

870868
static struct console netconsole_ext = {
871869
.name = "netcon_ext",
872-
.flags = CON_EXTENDED, /* starts disabled, registered on first use */
870+
.flags = CON_ENABLED | CON_EXTENDED,
873871
.write = write_ext_msg,
874872
};
875873

@@ -883,6 +881,7 @@ static int __init init_netconsole(void)
883881
{
884882
int err;
885883
struct netconsole_target *nt, *tmp;
884+
bool extended = false;
886885
unsigned long flags;
887886
char *target_config;
888887
char *input = config;
@@ -895,11 +894,12 @@ static int __init init_netconsole(void)
895894
goto fail;
896895
}
897896
/* Dump existing printks when we register */
898-
if (nt->extended)
899-
netconsole_ext.flags |= CON_PRINTBUFFER |
900-
CON_ENABLED;
901-
else
897+
if (nt->extended) {
898+
extended = true;
899+
netconsole_ext.flags |= CON_PRINTBUFFER;
900+
} else {
902901
netconsole.flags |= CON_PRINTBUFFER;
902+
}
903903

904904
spin_lock_irqsave(&target_list_lock, flags);
905905
list_add(&nt->list, &target_list);
@@ -915,7 +915,7 @@ static int __init init_netconsole(void)
915915
if (err)
916916
goto undonotifier;
917917

918-
if (netconsole_ext.flags & CON_ENABLED)
918+
if (extended)
919919
register_console(&netconsole_ext);
920920
register_console(&netconsole);
921921
pr_info("network logging started\n");
@@ -945,7 +945,8 @@ static void __exit cleanup_netconsole(void)
945945
{
946946
struct netconsole_target *nt, *tmp;
947947

948-
unregister_console(&netconsole_ext);
948+
if (console_is_registered(&netconsole_ext))
949+
unregister_console(&netconsole_ext);
949950
unregister_console(&netconsole);
950951
dynamic_netconsole_exit();
951952
unregister_netdevice_notifier(&netconsole_netdev_notifier);

0 commit comments

Comments
 (0)