From: Steven Rostedt <rostedt@goodmis.org>
To: Aleksey Makarov <aleksey.makarov@linaro.org>
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
Sudeep Holla <sudeep.holla@arm.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Peter Hurley <peter@hurleysoftware.com>,
Jiri Slaby <jslaby@suse.com>, Robin Murphy <robin.murphy@arm.com>,
Petr Mladek <pmladek@suse.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: Re: [PATCH 2/2] printk: fix double printing with earlycon
Date: Wed, 1 Mar 2017 21:29:48 -0500 [thread overview]
Message-ID: <20170301212948.3989bd14@grimm.local.home> (raw)
In-Reply-To: <20170301161347.4202-3-aleksey.makarov@linaro.org>
On Wed, 1 Mar 2017 19:13:46 +0300
Aleksey Makarov <aleksey.makarov@linaro.org> wrote:
> If a console was specified by ACPI SPCR table _and_
> command line parameters like "console=ttyAMA0" _and_ "earlycon"
> were specified, then log messages appears twice.
>
> The root cause is that the code traverse the list
> of specified consoles (the `console_cmdline` array) and stops at the
> first match. But it may happen that the same console is referred by
> the elements of this array twice:
>
> ttyAMA0 -- from command line
> pl011,mmio,0x87e024000000,115200 -- from SPCR
>
> but in this case `preferred_console` points to the second entry and
> the flag CON_CONSDEV is not set, so bootconsole is not deregistered.
>
> To fix that, match the console against the `console_cmdline` entry
> pointed by `preferred_console` instead of the first match.
>
> Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
> ---
> kernel/printk/printk.c | 52 ++++++++++++++++++++++++++++++--------------------
> 1 file changed, 31 insertions(+), 21 deletions(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index ed2a9b31f214..92008ae9db3f 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -2380,6 +2380,24 @@ static int __init keep_bootcon_setup(char *str)
>
> early_param("keep_bootcon", keep_bootcon_setup);
>
> +static int match_console(struct console *newcon, struct console_cmdline *c)
> +{
> + if (!newcon->match ||
> + newcon->match(newcon, c->name, c->index, c->options) != 0) {
> + /* default matching */
> + BUILD_BUG_ON(sizeof(c->name) != sizeof(newcon->name));
> + if (strcmp(c->name, newcon->name) != 0)
> + return -ENODEV;
> + if (newcon->index >= 0 &&
> + newcon->index != c->index)
> + return -ENODEV;
> + if (newcon->index < 0)
> + newcon->index = c->index;
> + }
> +
> + return 0;
> +}
> +
> /*
> * The console driver calls this routine during kernel initialization
> * to register the console printing procedure with printk() and to
> @@ -2460,37 +2478,29 @@ void register_console(struct console *newcon)
> for (i = 0, c = console_cmdline;
> i < MAX_CMDLINECONSOLES && c->name[0];
> i++, c++) {
> - if (!newcon->match ||
> - newcon->match(newcon, c->name, c->index, c->options) != 0) {
> - /* default matching */
> - BUILD_BUG_ON(sizeof(c->name) != sizeof(newcon->name));
> - if (strcmp(c->name, newcon->name) != 0)
> - continue;
> - if (newcon->index >= 0 &&
> - newcon->index != c->index)
> - continue;
> - if (newcon->index < 0)
> - newcon->index = c->index;
> + if (match_console(newcon, c))
> + continue;
>
> - if (_braille_register_console(newcon, c))
> - return;
> + if (_braille_register_console(newcon, c))
> + return;
>
> - if (newcon->setup &&
> - newcon->setup(newcon, c->options) != 0)
> - break;
> - }
> + if (newcon->setup &&
> + newcon->setup(newcon, c->options) != 0)
> + break;
>
> newcon->flags |= CON_ENABLED;
> - if (i == preferred_console) {
> - newcon->flags |= CON_CONSDEV;
> - has_preferred = true;
> - }
> break;
> }
>
> if (!(newcon->flags & CON_ENABLED))
> return;
>
We could use a comment right about here, explaining why the below is
needed.
-- Steve
> + if (preferred_console >= 0 &&
> + match_console(newcon, console_cmdline + preferred_console) == 0) {
> + newcon->flags |= CON_CONSDEV;
> + has_preferred = true;
> + }
> +
> /*
> * If we have a bootconsole, and are switching to a real console,
> * don't print everything out again, since when the boot console, and
prev parent reply other threads:[~2017-03-02 2:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-01 16:13 [PATCH 0/2] printk: fix double printing with earlycon Aleksey Makarov
2017-03-01 16:13 ` [PATCH 1/2] printk: fix name and type of some variables Aleksey Makarov
2017-03-02 2:24 ` Steven Rostedt
2017-03-01 16:13 ` [PATCH 2/2] printk: fix double printing with earlycon Aleksey Makarov
2017-03-02 2:29 ` Steven Rostedt [this message]
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=20170301212948.3989bd14@grimm.local.home \
--to=rostedt@goodmis.org \
--cc=aleksey.makarov@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=peter@hurleysoftware.com \
--cc=pmladek@suse.com \
--cc=robin.murphy@arm.com \
--cc=sergey.senozhatsky@gmail.com \
--cc=sudeep.holla@arm.com \
/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