From patchwork Wed Mar 1 16:13:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 94719 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1873165qgi; Wed, 1 Mar 2017 08:18:09 -0800 (PST) X-Received: by 10.98.221.141 with SMTP id w135mr9668303pff.109.1488385089199; Wed, 01 Mar 2017 08:18:09 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a62si4965175pgc.371.2017.03.01.08.18.08; Wed, 01 Mar 2017 08:18:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753229AbdCAQRy (ORCPT + 25 others); Wed, 1 Mar 2017 11:17:54 -0500 Received: from mail-lf0-f45.google.com ([209.85.215.45]:33012 "EHLO mail-lf0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752889AbdCAQRr (ORCPT ); Wed, 1 Mar 2017 11:17:47 -0500 Received: by mail-lf0-f45.google.com with SMTP id a6so21734999lfa.0 for ; Wed, 01 Mar 2017 08:17:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cXs+g7fOKkdbPf/3uuqzy2oqMCO/ud/nzpCSpaj05xE=; b=OSbD+lazBdKC02Wu5TqREcBteAX03Cdpg/Uw/n+cRG2rMGF4cQZizOn2lCuUDfKSk9 yGsDlG75yhoG/nXbkhuAT0FbL8mfugz5H1uyqXyXPTuNMImA8ki1lWAHaYEEJNZjrsDR Q7G8SDw4+SO0N7Y4q3ebTp1HpVYefl/v39cqI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cXs+g7fOKkdbPf/3uuqzy2oqMCO/ud/nzpCSpaj05xE=; b=EX3sr2R6UfcO+qGFjyfMJ+ljWOn5F3PpqT3eVihMfyyOpGh4dyA/Q0PKoSywSFDJbj k+2TJZeVSrEKDsexNzCjXF+WLlfEorMWc8DoyqQ8JpPQ6CCH6AmmAGSz0Mc+R64ewkiq ZGZah77Be52HvUm0qGmeD5EbmRbYY4NwdlP8+zE8ZlLfd+BAEwetYFldlNtB0tzJFOGi dt+vV9hinjZwdQwbOBZPjXzp1TVMX+qTw6RCe6SZVwttcKzLtgVenmmRobFFSYWHhNaQ cVumkDaU7H6xhWx/NXJBxaV0CtaFzk53LuTCOBRLHgScpp4IWf3T0XLeMEkbG2/1Frfa qVVg== X-Gm-Message-State: AMke39lR/D4rDeXDGh7HR9M7SyKlD70/4ODAqt3yGnHqmJgw9YKUIrQnLZjVh/BtdtF/WqmN X-Received: by 10.25.79.69 with SMTP id a5mr2930636lfk.58.1488385065055; Wed, 01 Mar 2017 08:17:45 -0800 (PST) Received: from localhost.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id x64sm1161937lfd.15.2017.03.01.08.17.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Mar 2017 08:17:44 -0800 (PST) From: Aleksey Makarov To: linux-serial@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Aleksey Makarov , Sudeep Holla , Greg Kroah-Hartman , Peter Hurley , Jiri Slaby , Robin Murphy , Petr Mladek , Sergey Senozhatsky , Steven Rostedt Subject: [PATCH 1/2] printk: fix name and type of some variables Date: Wed, 1 Mar 2017 19:13:45 +0300 Message-Id: <20170301161347.4202-2-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170301161347.4202-1-aleksey.makarov@linaro.org> References: <20170301161347.4202-1-aleksey.makarov@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The variable preferred_console is used only inside register_console() and its semantics is boolean. It is negative when no console has been made preferred. The variable selected_console holds an index into the console_cmdline array, pointing to the console that was made preferred. Rename the variables: selected_console -> preferred_console preferred_console -> has_preferred and make the new has_preferred local static bool. Renaming was suggested by Peter Hurley Signed-off-by: Aleksey Makarov Tested-by: Christopher Covington --- kernel/printk/printk.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) -- 2.11.1 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 34da86e73d00..ed2a9b31f214 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -267,7 +267,6 @@ static struct console *exclusive_console; static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES]; -static int selected_console = -1; static int preferred_console = -1; int console_set_on_cmdline; EXPORT_SYMBOL(console_set_on_cmdline); @@ -1908,14 +1907,14 @@ static int __add_preferred_console(char *name, int idx, char *options, i++, c++) { if (strcmp(c->name, name) == 0 && c->index == idx) { if (!brl_options) - selected_console = i; + preferred_console = i; return 0; } } if (i == MAX_CMDLINECONSOLES) return -E2BIG; if (!brl_options) - selected_console = i; + preferred_console = i; strlcpy(c->name, name, sizeof(c->name)); c->options = options; braille_set_options(c, brl_options); @@ -2406,6 +2405,7 @@ void register_console(struct console *newcon) unsigned long flags; struct console *bcon = NULL; struct console_cmdline *c; + static bool has_preferred; if (console_drivers) for_each_console(bcon) @@ -2432,15 +2432,15 @@ void register_console(struct console *newcon) if (console_drivers && console_drivers->flags & CON_BOOT) bcon = console_drivers; - if (preferred_console < 0 || bcon || !console_drivers) - preferred_console = selected_console; + if (!has_preferred || bcon || !console_drivers) + has_preferred = preferred_console >= 0; /* * See if we want to use this console driver. If we * didn't select a console we take the first one * that registers here. */ - if (preferred_console < 0) { + if (!has_preferred) { if (newcon->index < 0) newcon->index = 0; if (newcon->setup == NULL || @@ -2448,7 +2448,7 @@ void register_console(struct console *newcon) newcon->flags |= CON_ENABLED; if (newcon->device) { newcon->flags |= CON_CONSDEV; - preferred_console = 0; + has_preferred = true; } } } @@ -2481,9 +2481,9 @@ void register_console(struct console *newcon) } newcon->flags |= CON_ENABLED; - if (i == selected_console) { + if (i == preferred_console) { newcon->flags |= CON_CONSDEV; - preferred_console = selected_console; + has_preferred = true; } break; } From patchwork Wed Mar 1 16:13:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 94720 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1873177qgi; Wed, 1 Mar 2017 08:18:11 -0800 (PST) X-Received: by 10.84.175.132 with SMTP id t4mr11302942plb.38.1488385091118; Wed, 01 Mar 2017 08:18:11 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a62si4965175pgc.371.2017.03.01.08.18.10; Wed, 01 Mar 2017 08:18:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753246AbdCAQSJ (ORCPT + 25 others); Wed, 1 Mar 2017 11:18:09 -0500 Received: from mail-lf0-f46.google.com ([209.85.215.46]:36521 "EHLO mail-lf0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753219AbdCAQRw (ORCPT ); Wed, 1 Mar 2017 11:17:52 -0500 Received: by mail-lf0-f46.google.com with SMTP id y193so21692284lfd.3 for ; Wed, 01 Mar 2017 08:17:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=34ZeEgx56ZRFlYLbgQ/OdNuR5SWjfrOpO6Aa/X0p7Jg=; b=BByZogn6bq9snAo6BwGZycg7KuyVE7MrCLdO9F7YsJMQFhYtqanbb8C8kg0KAwtJs6 WxqjAyCWlB1Ru6tlkknIVfpMUQzjYiO5hLxAcTBxARBfmHxYqXpfj0y7L8OWWcfyW18J Oj2aFx9TQReg28q7lpAoqHiEfAGASFhrmLTB0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=34ZeEgx56ZRFlYLbgQ/OdNuR5SWjfrOpO6Aa/X0p7Jg=; b=N/TKLuM17O+X5F6BSocmw1jUPJ33+WJSyNAQyKcZoFrxCe1O761fcKKmPG0wdDZmmA hrvGgTyCJ055LjG0qdWOZDCMvHEyRs9F6d+R7mJ7XoecFLrHzFxTQRa845++08NQmQsN 7XzM+Qu5zsTiLvG1iH2tte6dHD4D9toOkXFC66iFIuB9q7iJJgUZAI/FpleYwSFu0o5o 6CamE4B0ZMdoMuLqPbQRbX5yuFyTsSuR8/WsmQzSIRTdhUigcechf+HxJvJ10lsWXtn3 KNU6Z5Ysrzh0a8LLlCpa4y3FyrR5dXb/Iokmjj/ZSu/YgACYs1b+DGKYheDuWKpUQeRe pqIQ== X-Gm-Message-State: AMke39n4ffwfTuwBGsF20MRIa+dMmhUJ1GXJvKnkiqWsXMMJUvwKTtJK1Lw2jjo/foYaclSm X-Received: by 10.46.8.18 with SMTP id 18mr3232275lji.35.1488385069328; Wed, 01 Mar 2017 08:17:49 -0800 (PST) Received: from localhost.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id x64sm1161937lfd.15.2017.03.01.08.17.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Mar 2017 08:17:48 -0800 (PST) From: Aleksey Makarov To: linux-serial@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Aleksey Makarov , Sudeep Holla , Greg Kroah-Hartman , Peter Hurley , Jiri Slaby , Robin Murphy , Petr Mladek , Sergey Senozhatsky , Steven Rostedt Subject: [PATCH 2/2] printk: fix double printing with earlycon Date: Wed, 1 Mar 2017 19:13:46 +0300 Message-Id: <20170301161347.4202-3-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170301161347.4202-1-aleksey.makarov@linaro.org> References: <20170301161347.4202-1-aleksey.makarov@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.11.1 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; + 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