From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753111AbdC0OPI (ORCPT ); Mon, 27 Mar 2017 10:15:08 -0400 Received: from mx2.suse.de ([195.135.220.15]:35674 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752607AbdC0OO4 (ORCPT ); Mon, 27 Mar 2017 10:14:56 -0400 Date: Mon, 27 Mar 2017 16:14:33 +0200 From: Petr Mladek To: Aleksey Makarov Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Sudeep Holla , Greg Kroah-Hartman , Peter Hurley , Jiri Slaby , Robin Murphy , Steven Rostedt , "Nair, Jayachandran" , Sergey Senozhatsky Subject: Re: [PATCH v8 3/3] printk: fix double printing with earlycon Message-ID: <20170327141432.GH2846@pathway.suse.cz> References: <20170315102854.1763-1-aleksey.makarov@linaro.org> <20170320100302.8656-1-aleksey.makarov@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170320100302.8656-1-aleksey.makarov@linaro.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 2017-03-20 13:03:00, 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, introduce an invariant "The last non-braille console > is always the preferred one" on the entries of the console_cmdline > array. Then traverse it in reverse order to be sure that if > the console is preferred then it will be the first matching entry. Sigh, I am afraid that we need to go this way. I hate the side effects of the match() functions. It would be great to get rid of them. But it is non-trivial and out of scope for this fix. > Reported-by: Sudeep Holla > Signed-off-by: Aleksey Makarov > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index fd752f0c8ef1..462036e7a767 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -1909,8 +1909,28 @@ static int __add_preferred_console(char *name, int idx, char *options, > i < MAX_CMDLINECONSOLES && c->name[0]; > i++, c++) { > if (strcmp(c->name, name) == 0 && c->index == idx) { > - if (!brl_options) > - preferred_console = i; > + int last; > + > + if (brl_options) > + return 0; > + > + /* > + * Maintain an invariant that will help to find if > + * the matching console is preferred, see > + * register_console(): > + * > + * The last non-braille console is always > + * the preferred one. > + */ > + for (last = MAX_CMDLINECONSOLES - 1; > + last >= 0 && !console_cmdline[last].name[0]; > + last--) > + ; This is a rather non-trivial code to find the last element. I might make sense to count it in a global variable. Then we might remove the check for console_cmdline[i].name[0] also in the other for cycles and make them better readable. > + > + if (i != last) > + swap(console_cmdline[i], console_cmdline[last]); I was not aware of the swap() function. It is great to know ;-) Otherwise, I am find with this approach. Best Regards, Petr