[PATCH v6 07/11] printk: Constrain hardware-addressed console checks to name position

Chris Down posted 11 patches 3 weeks, 6 days ago
[PATCH v6 07/11] printk: Constrain hardware-addressed console checks to name position
Posted by Chris Down 3 weeks, 6 days ago
Commit 7640f1a44eba ("printk: Add
match_devname_and_update_preferred_console()") adds support for
DEVNAME:n:n style console= registration. It determines whether or not
this is a hardware-addressed console by looking at whether the console=
string has a colon in it. However, this interferes with loglevel:n and
potentially other future named options, which also make use of the
character.

In order to avoid this, only search positions before options.

Signed-off-by: Chris Down <chris@chrisdown.name>
---
 kernel/printk/printk.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index bc456f7624d4..bbd037b84a0d 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2670,6 +2670,7 @@ static int __init console_setup(char *str)
 	char *devname = NULL;
 	char *options;
 	char *s;
+	char *first_delim;
 	int idx;
 
 	/*
@@ -2685,8 +2686,13 @@ static int __init console_setup(char *str)
 	if (_braille_console_setup(&str, &brl_options))
 		return 1;
 
-	/* For a DEVNAME:0.0 style console the character device is unknown early */
-	if (strchr(str, ':'))
+	/*
+	 * For a DEVNAME:0.0 style console the character device is unknown
+	 * early. We must restrict this to before any comma to avoid interfering
+	 * with named options, like "loglevel".
+	 */
+	first_delim = strpbrk(str, ":,");
+	if (first_delim && *first_delim == ':')
 		devname = buf;
 	else
 		ttyname = buf;
-- 
2.46.0
Re: [PATCH v6 07/11] printk: Constrain hardware-addressed console checks to name position
Posted by Petr Mladek 1 week, 4 days ago
On Mon 2024-10-28 16:45:48, Chris Down wrote:
> Commit 7640f1a44eba ("printk: Add
> match_devname_and_update_preferred_console()") adds support for
> DEVNAME:n:n style console= registration. It determines whether or not
> this is a hardware-addressed console by looking at whether the console=
> string has a colon in it. However, this interferes with loglevel:n and
> potentially other future named options, which also make use of the
> character.
> 
> In order to avoid this, only search positions before options.
> 
> Signed-off-by: Chris Down <chris@chrisdown.name>

Nice trick!

Reviewed-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr
Re: [PATCH v6 07/11] printk: Constrain hardware-addressed console checks to name position
Posted by Tony Lindgren 3 weeks, 6 days ago
On Mon, Oct 28, 2024 at 04:45:48PM +0000, Chris Down wrote:
> Commit 7640f1a44eba ("printk: Add
> match_devname_and_update_preferred_console()") adds support for
> DEVNAME:n:n style console= registration. It determines whether or not
> this is a hardware-addressed console by looking at whether the console=
> string has a colon in it. However, this interferes with loglevel:n and
> potentially other future named options, which also make use of the
> character.
> 
> In order to avoid this, only search positions before options.

Looks good to me:

Reviewed-by: Tony Lindgren <tony.lindgren@linux.intel.com>