Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753872AbdCBDYq (ORCPT ); Wed, 1 Mar 2017 22:24:46 -0500 Received: from smtprelay0088.hostedemail.com ([216.40.44.88]:45668 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753836AbdCBDYp (ORCPT ); Wed, 1 Mar 2017 22:24:45 -0500 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::::::::,RULES_HIT:41:69:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1431:1437:1515:1516:1518:1534:1543:1593:1594:1605:1711:1730:1747:1777:1792:2393:2553:2559:2562:2898:3138:3139:3140:3141:3142:3622:3865:3866:3867:3868:3870:3871:3872:3874:4321:5007:6117:6119:6261:6691:7875:7903:7904:9010:10004:10400:10482:10848:10967:11026:11232:11473:11658:11914:12043:12291:12295:12296:12438:12555:12683:12740:12760:12895:12986:13439:13972:14096:14097:14181:14659:14721:19901:19997:21063:21080:21433:21451:30012:30029:30054:30062:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:3,LUA_SUMMARY:none X-HE-Tag: chain88_72eabf2ff0e46 X-Filterd-Recvd-Size: 4902 Date: Wed, 1 Mar 2017 21:29:48 -0500 From: Steven Rostedt 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 , Petr Mladek , Sergey Senozhatsky Subject: Re: [PATCH 2/2] printk: fix double printing with earlycon Message-ID: <20170301212948.3989bd14@grimm.local.home> In-Reply-To: <20170301161347.4202-3-aleksey.makarov@linaro.org> References: <20170301161347.4202-1-aleksey.makarov@linaro.org> <20170301161347.4202-3-aleksey.makarov@linaro.org> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3617 Lines: 112 On Wed, 1 Mar 2017 19:13:46 +0300 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 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 > --- > 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