public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andre Kalb <svc.sw.rte.linux@sma.de>
To: <pmladek@suse.com>, <senozhatsky@chromium.org>
Cc: <andre.kalb@sma.de>, <john.ogness@linutronix.de>,
	<linux-kernel@vger.kernel.org>, <rostedt@goodmis.org>
Subject: [PATCH v3] printk: Set console_set_on_cmdline=1 when __add_preferred_console() is called with user_specified == true
Date: Wed, 16 Feb 2022 11:41:38 +0100	[thread overview]
Message-ID: <YgzU4ho8l6XapyG2@pc6682> (raw)
In-Reply-To: <YgxtGWh0b9NXTyu8@google.com>

From: Andre Kalb <andre.kalb@sma.de>

In case of using console="" or console=null
set console_set_on_cmdline=1 to disable "stdout-path" node from DT.

We basically need to set it every time when __add_preferred_console()
is called with parameter 'user_specified' set.
Therefore we can move setting it into a helper function that is
called from __add_preferred_console().

Suggested-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Andre Kalb <andre.kalb@sma.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
Changelog v1 to v2:
Move console_set_on_cmdling into separate function set_user_specified(), which is called from
__add_preferred_console().

The old patch v1 could be used to backport to stable 5.4 and lower.

Changelog v2 to v3:
Add comment to explain the less obvious behaviour.
---
 kernel/printk/printk.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 82abfaf3c2aa..e4e1a5266108 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2324,6 +2324,20 @@ asmlinkage __visible void early_printk(const char *fmt, ...)
 }
 #endif
 
+static void set_user_specified(struct console_cmdline *c, bool user_specified)
+{
+	if (!user_specified)
+		return;
+
+	/*
+	 * @c console was defined by the user on the command line.
+	 * Do not clear when added twice also by SPCR or the device tree.
+	 */
+	c->user_specified = true;
+	/* At least one console defined by the user on the command line. */
+	console_set_on_cmdline = 1;
+}
+
 static int __add_preferred_console(char *name, int idx, char *options,
 				   char *brl_options, bool user_specified)
 {
@@ -2340,8 +2354,7 @@ static int __add_preferred_console(char *name, int idx, char *options,
 		if (strcmp(c->name, name) == 0 && c->index == idx) {
 			if (!brl_options)
 				preferred_console = i;
-			if (user_specified)
-				c->user_specified = true;
+			set_user_specified(c, user_specified);
 			return 0;
 		}
 	}
@@ -2351,7 +2364,7 @@ static int __add_preferred_console(char *name, int idx, char *options,
 		preferred_console = i;
 	strlcpy(c->name, name, sizeof(c->name));
 	c->options = options;
-	c->user_specified = user_specified;
+	set_user_specified(c, user_specified);
 	braille_set_options(c, brl_options);
 
 	c->index = idx;
@@ -2417,7 +2430,6 @@ static int __init console_setup(char *str)
 	*s = 0;
 
 	__add_preferred_console(buf, idx, options, brl_options, true);
-	console_set_on_cmdline = 1;
 	return 1;
 }
 __setup("console=", console_setup);
-- 
2.31.1


  reply	other threads:[~2022-02-16 10:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-27 23:00 [PATCH] printk: Set console_set_on_cmdline=1 when using console="" or console=null Andre Kalb
2022-02-08 15:55 ` Petr Mladek
2022-02-14 13:21   ` [PATCH v2] printk: Set console_set_on_cmdline=1 when __add_preferred_console() is called with user_specified == true Andre Kalb
2022-02-15  3:15     ` Sergey Senozhatsky
2022-02-15 17:58       ` Petr Mladek
2022-02-15 18:10     ` Petr Mladek
2022-02-16  3:18       ` Sergey Senozhatsky
2022-02-16 10:41         ` Andre Kalb [this message]
2022-02-21 15:49           ` [PATCH v3] " 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=YgzU4ho8l6XapyG2@pc6682 \
    --to=svc.sw.rte.linux@sma.de \
    --cc=andre.kalb@sma.de \
    --cc=john.ogness@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@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