From patchwork Thu Mar 2 13:11:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 94779 Delivered-To: patch@linaro.org Received: by 10.140.82.71 with SMTP id g65csp156166qgd; Thu, 2 Mar 2017 05:15:45 -0800 (PST) X-Received: by 10.98.144.22 with SMTP id a22mr15671516pfe.160.1488460545037; Thu, 02 Mar 2017 05:15:45 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p67si7435871pfb.136.2017.03.02.05.15.44; Thu, 02 Mar 2017 05:15:45 -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 S1752938AbdCBNPd (ORCPT + 25 others); Thu, 2 Mar 2017 08:15:33 -0500 Received: from mail-lf0-f52.google.com ([209.85.215.52]:33494 "EHLO mail-lf0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752883AbdCBNP2 (ORCPT ); Thu, 2 Mar 2017 08:15:28 -0500 Received: by mail-lf0-f52.google.com with SMTP id a6so33462017lfa.0 for ; Thu, 02 Mar 2017 05:15:26 -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=e7pf7RM8jn55qXpwCWDlTjK2RW7rh4DjxEXexeBIep8=; b=P87D9UroD9dyjkmfxqWl2iDsKQFD70p4V3e1EuEvN0vPWZtE7pMybIYhBoGDrHIP09 DtAoqRfLzDyCvkqDRHOav481NqBorKdtBYKcoBMpWV2z7+0yYQFXMSvSw6F4QMdLpy6p HSAlZyNf4Wlp1x82ACa0qhRv1EBQnFONPeVt8= 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=e7pf7RM8jn55qXpwCWDlTjK2RW7rh4DjxEXexeBIep8=; b=XJZ/TK7mSBQBFdPOvdyXWm+baTNSaPoAGoxDxdf+1p80AAxq41XmgGFh9HV66kXI2v d53NdRoxruBkJVtYQXbtSrmigK8pNB56hWgoVGytX8NAHLihCotsaYWjzA8LJcb3E6zJ a/UnnwxCKUIS2ajBq/pZzNdrTSY6MVl49SD77lUCaQTMcvbi6M+mYtU0ODEwEwzFeF2R PaVRrzIIy9q91i9YWxntbHg7jJehQnvAslBSIS/VBLlF9o5oeeqFisqNy/GMl97LzXss fJDv2jM5IQCkTYI04VkMEMq8wnU3IzIMPpnwkLEclsqNNJyodt6/3QqPGs5MN9hqNHTL ZJ1w== X-Gm-Message-State: AMke39k+E7HlxEfCI5VQoZUQoTPo13e42Dm2FznKTj85dzO9eQxXNg4gTMix/5/iX/jND982 X-Received: by 10.25.79.69 with SMTP id a5mr4439646lfk.58.1488460520886; Thu, 02 Mar 2017 05:15:20 -0800 (PST) Received: from localhost.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id c69sm1696062lfe.23.2017.03.02.05.15.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Mar 2017 05:15:20 -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 , Steven Rostedt , "Nair, Jayachandran" , Petr Mladek , Sergey Senozhatsky Subject: [PATCH v2 1/3] printk: fix name/type/scope of preferred_console var Date: Thu, 2 Mar 2017 16:11:32 +0300 Message-Id: <20170302131153.22733-2-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170302131153.22733-1-aleksey.makarov@linaro.org> References: <20170302131153.22733-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. Make it static bool and rename to has_preferred. Renaming was suggested by Peter Hurley Signed-off-by: Aleksey Makarov --- kernel/printk/printk.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.11.1 Reviewed-by: Steven Rostedt (VMware) Reviewed-by: Sergey Senozhatsky diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 34da86e73d00..3c2234f21291 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -268,7 +268,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); @@ -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 = selected_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; } } } @@ -2483,7 +2483,7 @@ void register_console(struct console *newcon) newcon->flags |= CON_ENABLED; if (i == selected_console) { newcon->flags |= CON_CONSDEV; - preferred_console = selected_console; + has_preferred = true; } break; } From patchwork Thu Mar 2 13:11:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 94781 Delivered-To: patch@linaro.org Received: by 10.140.82.71 with SMTP id g65csp156189qgd; Thu, 2 Mar 2017 05:15:48 -0800 (PST) X-Received: by 10.98.91.131 with SMTP id p125mr15526219pfb.165.1488460548109; Thu, 02 Mar 2017 05:15:48 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p67si7435871pfb.136.2017.03.02.05.15.47; Thu, 02 Mar 2017 05:15:48 -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 S1753019AbdCBNPr (ORCPT + 25 others); Thu, 2 Mar 2017 08:15:47 -0500 Received: from mail-lf0-f44.google.com ([209.85.215.44]:33507 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752981AbdCBNPn (ORCPT ); Thu, 2 Mar 2017 08:15:43 -0500 Received: by mail-lf0-f44.google.com with SMTP id a6so33462564lfa.0 for ; Thu, 02 Mar 2017 05:15:24 -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=++Kkz3yyivhUg6/ctQuvIzYkzCf9aB0zsZNM8hsCKBk=; b=YApvBanBTDuSyMtICZkNXCkNi1wHtxz0HRrYdui6U5AevAsQ0rFtNCnHQW9J2SKJ6w stZhIcym7KD7y0ihUftsc0ArAmekMM+yop35fdvapFDY7tm4vifBi8L4KkmL80njwkHC +mTdF9RlWkpYW9RzRGJH00gRhiVf9BNo9o9H0= 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=++Kkz3yyivhUg6/ctQuvIzYkzCf9aB0zsZNM8hsCKBk=; b=XL8cKrUWDr4eGgPg8YZCta3Kv5WlX4hCSBkA0mOY+mM0VHpgJBHb9zD53svCMgzq0a 7rMVy958YnyhLhOuM3mCpdDfm+Fx0OrWFmJfE4YrMRqgzc/EPLJA5GUKHGct23r2AieS 3nPEeEQvk7rOzumZ0MAZAIUZEvayRNqG/KhCNJUlGTjCbSkauoQoj1uKqVThJWM/f9Ce wQR8TuXBJmn4zk/qBw1A5dM3WYhl4NhY4Jvc8uCy4cpox7CWm2fnuroO0IW+p6Rs5L5m TWrUOYvFeILkUW6/aPwc4nuucnCAhP7tTN3yBNfqRhaHSfcYwYKLGjz4layJ/yFl/wYx No4Q== X-Gm-Message-State: AMke39lzeWhCWnb9UlyUbWd0/nWmIj1NioQmrNVwoscZaJhrk0yYYMb/xXci+Hhs0+eqlcNx X-Received: by 10.25.19.194 with SMTP id 63mr4557693lft.144.1488460523681; Thu, 02 Mar 2017 05:15:23 -0800 (PST) Received: from localhost.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id c69sm1696062lfe.23.2017.03.02.05.15.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Mar 2017 05:15:23 -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 , Steven Rostedt , "Nair, Jayachandran" , Petr Mladek , Sergey Senozhatsky Subject: [PATCH v2 2/3] printk: rename selected_console -> preferred_console Date: Thu, 2 Mar 2017 16:11:33 +0300 Message-Id: <20170302131153.22733-3-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170302131153.22733-1-aleksey.makarov@linaro.org> References: <20170302131153.22733-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 selected_console is set in __add_preferred_console() to point to the last console parameter that was added to the console_cmdline array. Rename it to preferred_console so that the name reflects the usage. Suggested-by: Peter Hurley Signed-off-by: Aleksey Makarov --- kernel/printk/printk.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.11.1 Acked-by: Steven Rostedt (VMware) Acked-by: Petr Mladek diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 3c2234f21291..ed2a9b31f214 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -267,7 +267,7 @@ 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); @@ -1907,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); @@ -2433,7 +2433,7 @@ void register_console(struct console *newcon) bcon = console_drivers; if (!has_preferred || bcon || !console_drivers) - has_preferred = selected_console >= 0; + has_preferred = preferred_console >= 0; /* * See if we want to use this console driver. If we @@ -2481,7 +2481,7 @@ void register_console(struct console *newcon) } newcon->flags |= CON_ENABLED; - if (i == selected_console) { + if (i == preferred_console) { newcon->flags |= CON_CONSDEV; has_preferred = true; } From patchwork Thu Mar 2 13:11:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 94780 Delivered-To: patch@linaro.org Received: by 10.140.82.71 with SMTP id g65csp156169qgd; Thu, 2 Mar 2017 05:15:45 -0800 (PST) X-Received: by 10.98.147.10 with SMTP id b10mr15400510pfe.177.1488460545494; Thu, 02 Mar 2017 05:15:45 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p67si7435871pfb.136.2017.03.02.05.15.45; Thu, 02 Mar 2017 05:15:45 -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 S1752968AbdCBNPf (ORCPT + 25 others); Thu, 2 Mar 2017 08:15:35 -0500 Received: from mail-lf0-f51.google.com ([209.85.215.51]:33523 "EHLO mail-lf0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752894AbdCBNP3 (ORCPT ); Thu, 2 Mar 2017 08:15:29 -0500 Received: by mail-lf0-f51.google.com with SMTP id a6so33463239lfa.0 for ; Thu, 02 Mar 2017 05:15:28 -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=Ari5fNiglRIGlN9gahP0o0nPzt0FDjR1xqofjDfU9OI=; b=EhyjZTpmqMc+nyc78cKIp5qeFxPHOtbj4NfsZQ6rjIPa0OVwPHyPjl6PIbZoai4LGA bWSINgrkA11ejsFSXECcg1z6sllzeymC/C0S3XhDoe9zJ1qC66I5tUcY2q0DhF8Avbud erj058KVraeOu68G6pi150g2UHRKe3Zt//jLQ= 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=Ari5fNiglRIGlN9gahP0o0nPzt0FDjR1xqofjDfU9OI=; b=MR17NnfGTWdwFHIUVGs6VJTUqrQkvAWMeZdtx5o5bOTpcdYhbP3/WAZE3z4zp61YGh GfAsPJObeQA0nw12ZUU3fa1YcYlGq6Y0i0Q0h9YLrvlD9vk8EY9lrxEIx8YZSY9HqWKp PAHpa6q6CeNwWnd6/+k1riiFOQMtHug5T8P2wu4SxPWAzDSZ6QVTV5j/IXAhyGBd21k4 UGZO1nOET6XI0aEWw3ew0DrVKB0U8vQuj11yDn47czSRD2LK3iP/aQ9X0Cp71gjpA3Jq 7cBURvWr7HDw4u/Ty5XTMRMI04nWfIASueDkha0Oevpsra9z1wVUcft4ocpld3/r+54w AXqw== X-Gm-Message-State: AMke39kZg3+d3Le3p6ZoW71YhL4CC1fhm+UGoF7XYGTKlVa/9awoByiLmy0UH3EfUbrU9H5M X-Received: by 10.25.145.77 with SMTP id y13mr4059885lfj.49.1488460526882; Thu, 02 Mar 2017 05:15:26 -0800 (PST) Received: from localhost.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id c69sm1696062lfe.23.2017.03.02.05.15.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Mar 2017 05:15:26 -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 , Steven Rostedt , "Nair, Jayachandran" , Petr Mladek , Sergey Senozhatsky Subject: [PATCH v2 3/3] printk: fix double printing with earlycon Date: Thu, 2 Mar 2017 16:11:34 +0300 Message-Id: <20170302131153.22733-4-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170302131153.22733-1-aleksey.makarov@linaro.org> References: <20170302131153.22733-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 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 --- kernel/printk/printk.c | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) -- 2.11.1 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 { if (_braille_register_console(newcon, c)) return; @@ -2481,10 +2491,6 @@ void register_console(struct console *newcon) } newcon->flags |= CON_ENABLED; - if (i == preferred_console) { - newcon->flags |= CON_CONSDEV; - has_preferred = true; - } break; } @@ -2492,6 +2498,19 @@ void register_console(struct console *newcon) return; /* + * Check if this console was set as preferred by command line parameters + * or by call to add_preferred_console(). + * There may be several entries in the console_cmdline array referring + * to the same console so we can not just use the first match. Instead + * check the entry pointed by preferred_console explicitly. + */ + 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 * the real console are the same physical device, it's annoying to