From: Aleksey Makarov <aleksey.makarov@linaro.org>
To: linux-serial@vger.kernel.org
Cc: 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>,
Steven Rostedt <rostedt@goodmis.org>,
"Nair, Jayachandran" <Jayachandran.Nair@cavium.com>,
Petr Mladek <pmladek@suse.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: Re: [PATCH v2 3/3] printk: fix double printing with earlycon
Date: Thu, 2 Mar 2017 16:58:59 +0300 [thread overview]
Message-ID: <910be665-10e2-4b4f-990c-a3a8839cd054@linaro.org> (raw)
In-Reply-To: <20170302131153.22733-4-aleksey.makarov@linaro.org>
On 03/02/2017 04:11 PM, Aleksey Makarov wrote:
> If a console was specified by ACPI SPCR table _and_ command line
> parameters like "console=ttyAMA0" _and_ "earlycon" were specified,
> then log messages appear twice.
>
> The root cause is that the code traverses 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:
>
> pl011,mmio,0x87e024000000,115200 -- from SPCR
> ttyAMA0 -- from command line
>
> 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 | 49 ++++++++++++++++++++++++++++++++++---------------
> 1 file changed, 34 insertions(+), 15 deletions(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index ed2a9b31f214..ad35011f8374 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,17 +2478,9 @@ 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;
> + } else {
My bad. The first version of this patch was closer to the original logic,
despite this patch looks simpler.
The problem is that newcon->setup() is called twice, firstly from
newcon->match(), then explicitly. And it could be called third time later
in another call to newcon->match().
The correct sequence is 1) try to match against preferred_console,
2) if that fails check other entries of console_cmdline. That would require
some work so I will send a correction tomorrow.
All the best
Aleksey Makarov
next prev parent reply other threads:[~2017-03-02 14:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-02 13:11 [PATCH v2 0/3] " Aleksey Makarov
2017-03-02 13:11 ` [PATCH v2 1/3] printk: fix name/type/scope of preferred_console var Aleksey Makarov
2017-03-02 14:49 ` Steven Rostedt
2017-03-02 15:59 ` Sergey Senozhatsky
2017-03-14 16:52 ` Petr Mladek
2017-03-02 13:11 ` [PATCH v2 2/3] printk: rename selected_console -> preferred_console Aleksey Makarov
2017-03-02 15:01 ` Steven Rostedt
2017-03-02 16:09 ` Sergey Senozhatsky
2017-03-15 9:00 ` Petr Mladek
2017-03-02 13:11 ` [PATCH v2 3/3] printk: fix double printing with earlycon Aleksey Makarov
2017-03-02 13:58 ` Aleksey Makarov [this message]
2017-03-03 15:49 ` [PATCH v3 " Aleksey Makarov
2017-03-06 14:59 ` Sergey Senozhatsky
2017-03-07 14:54 ` Aleksey Makarov
2017-03-08 5:33 ` Sergey Senozhatsky
2017-03-08 12:59 ` Aleksey Makarov
2017-03-14 16:17 ` [PATCH v2 0/3] " Sudeep Holla
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=910be665-10e2-4b4f-990c-a3a8839cd054@linaro.org \
--to=aleksey.makarov@linaro.org \
--cc=Jayachandran.Nair@cavium.com \
--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=rostedt@goodmis.org \
--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
all inboxes | Powered by JetHome®