[PATCH v4 10/11] printk: Modify try_enable_default_console() to return error/success

From: Petr Mladek

Date: Thu Jun 04 2026 - 06:24:14 EST


Currently, try_enable_default_console() has a void return type, and
its potential failures (specifically when console_call_setup() fails)
are ignored by its caller, try_enable_console().

Modify try_enable_default_console() to return error/success, and update
try_enable_console() to capture and propagate this error.

With this change, try_enable_console() will no longer return success
for a pre-enabled console if try_enable_default_console() failed (such
as when newcon->setup() fails). While this might change existing behavior,
it is the correct approach to ensure setup errors are not silently ignored
or treated as successful registrations simply because the console was
marked pre-enabled.

Assisted-by: Gemini:gemini-3 # commit message
Signed-off-by: Petr Mladek <pmladek@xxxxxxxx>
---
kernel/printk/printk.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index a4eaf157cece..b0df4a23252d 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -4060,18 +4060,23 @@ static int try_enable_braille_console(struct console *newcon)
}

/* Try to enable the console unconditionally */
-static void try_enable_default_console(struct console *newcon)
+static int try_enable_default_console(struct console *newcon)
{
+ int err;
+
if (newcon->index < 0)
newcon->index = 0;

- if (console_call_setup(newcon, NULL) != 0)
- return;
+ err = console_call_setup(newcon, NULL);
+ if (err)
+ return err;

newcon->flags |= CON_ENABLED;

if (newcon->device)
newcon->flags |= CON_CONSDEV;
+
+ return 0;
}

#define console_first() \
@@ -4114,7 +4119,9 @@ static int try_enable_console(struct console *newcon)
if (preferred_dev_console < 0) {
if (hlist_empty(&console_list) || !console_first()->device ||
console_first()->flags & CON_BOOT) {
- try_enable_default_console(newcon);
+ err = try_enable_default_console(newcon);
+ if (err != -ENOENT)
+ return err;
}
}

--
2.54.0