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

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
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -332,10 +332,8 @@ static ssize_t enabled_store(struct config_item *item,
	}

	if (enabled) {	/* true */
		if (nt->extended && !(netconsole_ext.flags & CON_ENABLED)) {
			netconsole_ext.flags |= CON_ENABLED;
		if (nt->extended && !console_is_registered(&netconsole_ext))
			register_console(&netconsole_ext);
		}

		/*
		 * 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)

static struct console netconsole_ext = {
	.name	= "netcon_ext",
	.flags	= CON_EXTENDED,	/* starts disabled, registered on first use */
	.flags	= CON_ENABLED | CON_EXTENDED,
	.write	= write_ext_msg,
};

@@ -883,6 +881,7 @@ static int __init init_netconsole(void)
{
	int err;
	struct netconsole_target *nt, *tmp;
	bool extended = false;
	unsigned long flags;
	char *target_config;
	char *input = config;
@@ -895,11 +894,12 @@ static int __init init_netconsole(void)
				goto fail;
			}
			/* Dump existing printks when we register */
			if (nt->extended)
				netconsole_ext.flags |= CON_PRINTBUFFER |
							CON_ENABLED;
			else
			if (nt->extended) {
				extended = true;
				netconsole_ext.flags |= CON_PRINTBUFFER;
			} else {
				netconsole.flags |= CON_PRINTBUFFER;
			}

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

	if (netconsole_ext.flags & CON_ENABLED)
	if (extended)
		register_console(&netconsole_ext);
	register_console(&netconsole);
	pr_info("network logging started\n");
@@ -945,6 +945,7 @@ static void __exit cleanup_netconsole(void)
{
	struct netconsole_target *nt, *tmp;

	if (console_is_registered(&netconsole_ext))
		unregister_console(&netconsole_ext);
	unregister_console(&netconsole);
	dynamic_netconsole_exit();