public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Marcos Paulo de Souza <mpdesouza@suse.com>,
	Chris Down <chris@chrisdown.name>,
	linux-kernel@vger.kernel.org, Petr Mladek <pmladek@suse.com>
Subject: [PATCH v2 8/9] printk: Handle pre-enabled consoles in the top-level try_enable_console()
Date: Thu, 23 Apr 2026 15:00:13 +0200	[thread overview]
Message-ID: <20260423130015.85175-9-pmladek@suse.com> (raw)
In-Reply-To: <20260423130015.85175-1-pmladek@suse.com>

The function try_enable_preferred_console() currently has the
non-obvious side effect of returning success for consoles that are
already pre-enabled. This obscures the logic flow during console
registration.

Move the check for pre-enabled consoles directly into the top-level
try_enable_console(). This change makes the handling of pre-enabled
consoles explicit and easier to follow.

Furthermore, this separation lays the groundwork for future cleanups
where try_enable_preferred_console() can be restricted to cases where
an entry actually exists in the preferred_consoles[] array.

Possible behavior change:

try_enable_preferred_console() will newly be called also with
@user_specified parameter set to "false" when it failed with the "true"
variant. But it looks like the right way to do. It will allow to call
newcon->setup() when the console was preferred by some platform
specific code.

Signed-off-by: Petr Mladek <pmladek@suse.com>
---
 kernel/printk/printk.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9143a050c289..91c3be6843bc 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3988,9 +3988,6 @@ static int console_call_setup(struct console *newcon, char *options)
  * the newly registered console with any of the ones selected
  * by either the command line or add_preferred_console() and
  * setup/enable it.
- *
- * Care need to be taken with consoles that are statically
- * enabled such as netconsole
  */
 static int __try_enable_preferred_console(struct console *newcon,
 					  bool user_specified,
@@ -4043,14 +4040,6 @@ static int __try_enable_preferred_console(struct console *newcon,
 		return 0;
 	}
 
-	/*
-	 * Some consoles, such as pstore and netconsole, can be enabled even
-	 * without matching. Accept the pre-enabled consoles only when match()
-	 * and setup() had a chance to be called.
-	 */
-	if (newcon->flags & CON_ENABLED && pc->user_specified == user_specified)
-		return 0;
-
 	return -ENOENT;
 }
 
@@ -4130,7 +4119,19 @@ static int try_enable_console(struct console *newcon)
 		return err;
 
 	/* If not, try to match against the platform default(s) */
-	return try_enable_preferred_console(newcon, false);
+	err = try_enable_preferred_console(newcon, false);
+	if (err != -ENOENT)
+		return err;
+
+	/*
+	 * Some consoles, such as pstore and netconsole, can be enabled even
+	 * without matching. Accept them at this stage when they had a chance
+	 * to match() and call setup().
+	 */
+	if (newcon->flags & CON_ENABLED)
+		err = 0;
+
+	return err;
 }
 
 /* Return the starting sequence number for a newly registered console. */
-- 
2.53.0


  parent reply	other threads:[~2026-04-23 13:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-23 13:00 [PATCH v2 0/9] printk: Clean up preferred console handling Petr Mladek
2026-04-23 13:00 ` [PATCH v2 1/9] printk: Rename struct console_cmdline to preferred_console Petr Mladek
2026-04-23 14:16   ` Steven Rostedt
2026-04-23 13:00 ` [PATCH v2 2/9] printk: Rename preferred_console to preferred_dev_console Petr Mladek
2026-04-23 13:00 ` [PATCH v2 3/9] printk: Separate code for adding/updating preferred console metadata Petr Mladek
2026-04-23 13:00 ` [PATCH v2 4/9] printk: Cleanup _braille_(un)register_console() wrappers Petr Mladek
2026-04-23 13:00 ` [PATCH v2 5/9] printk: Separate code for enabling console Petr Mladek
2026-04-23 13:00 ` [PATCH v2 6/9] printk: Try to register each console as Braille first Petr Mladek
2026-04-23 13:00 ` [PATCH v2 7/9] printk: Do not set Braille console as preferred_console Petr Mladek
2026-04-23 13:00 ` Petr Mladek [this message]
2026-04-23 13:00 ` [PATCH v2 9/9] printk: Try enable preferred consoles only when there are any Petr Mladek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260423130015.85175-9-pmladek@suse.com \
    --to=pmladek@suse.com \
    --cc=chris@chrisdown.name \
    --cc=john.ogness@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpdesouza@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox