Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1591139
| From | Aleksey Makarov <aleksey.makarov@linaro.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v2 3/3] printk: fix double printing with earlycon |
| Date | 2017-03-02 15:40 +0100 |
| Message-ID | <tgA3D-3wp-1@gated-at.bofh.it> (permalink) |
| References | <tgyOd-2Mh-19@gated-at.bofh.it> <tgyOe-2Mh-23@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v2 3/3] printk: fix double printing with earlycon Aleksey Makarov <aleksey.makarov@linaro.org> - 2017-03-02 14:20 +0100
Re: [PATCH v2 3/3] printk: fix double printing with earlycon Aleksey Makarov <aleksey.makarov@linaro.org> - 2017-03-02 15:40 +0100
[PATCH v3 3/3] printk: fix double printing with earlycon Aleksey Makarov <aleksey.makarov@linaro.org> - 2017-03-03 17:00 +0100
Re: [PATCH v3 3/3] printk: fix double printing with earlycon Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-03-06 16:10 +0100
Re: [PATCH v3 3/3] printk: fix double printing with earlycon Aleksey Makarov <amakarov.linux@gmail.com> - 2017-03-07 16:10 +0100
Re: [PATCH v3 3/3] printk: fix double printing with earlycon Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2017-03-08 06:40 +0100
Re: [PATCH v3 3/3] printk: fix double printing with earlycon Aleksey Makarov <amakarov.linux@gmail.com> - 2017-03-08 16:00 +0100
csiph-web