[PATCH v7 06/17] printk: Prefer the console either via name or devname exclusively
From: Petr Mladek
Date: Wed Nov 11 2026 - 10:51:35 EST
The commit 7640f1a44eba ("printk: Add
match_devname_and_update_preferred_console()") added the possibility
to prefer a console driver via device name. The name of the console driver
gets assigned when the device gets initialized and it tries whether
it is eligible for a console.
The above mentioned commit ensures that __add_preferred_console() is called
at least with name or devname value. But it does not check whether
both are defined which is a nonsense.
Add the check and do not fail quietly.
Signed-off-by: Petr Mladek <pmladek@xxxxxxxx>
---
kernel/printk/printk.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 3ddbde5326d9..b139314eda70 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2561,6 +2561,12 @@ asmlinkage __visible void early_printk(const char *fmt, ...)
* in register_console(). Finally, it enforces some rules:
*
* 1. Do not accept empty @name or @devname.
+ *
+ * 2. Either @name OR @devname are allowed. [*]
+ *
+ * [*] A valid @name and @idx will get assigned for a devname later when
+ * @devname matches during the device initialization, see
+ * match_devname_and_update_preferred_console().
*/
static int add_or_update_preferred_console(unsigned int i,
const char *name, const short idx,
@@ -2583,6 +2589,12 @@ static int add_or_update_preferred_console(unsigned int i,
return -EINVAL;
}
+ if (name && devname) {
+ pr_err("Adding a preferred console devname with a hard-coded console name: %s, %s\n",
+ devname, name);
+ return -EINVAL;
+ }
+
/*
* We use a signed short index for struct console for device drivers to
* indicate a not yet assigned index or port. However, a negative index
--
2.56.0