aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Makarov <aleksey.makarov@linaro.org>2017-04-05 16:20:00 -0400
committerPetr Mladek <pmladek@suse.com>2017-04-12 05:40:22 -0400
commitcf39bf58afdaabc0b86f141630fb3fd18190294e (patch)
tree299a204a7447f5c84cdd1de0588b5e892c117cdd
parentad86ee2b8a47590f62a4f3bc1d25dc126d121cb9 (diff)
printk: fix double printing with earlycon
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. Introduce variable console_cmdline_cnt that keeps the number of elements of the console_cmdline array (Petr Mladek). It helps to get rid of the loop that searches for the end of this array. Link: http://lkml.kernel.org/r/20170405202006.18234-1-aleksey.makarov@linaro.org Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Peter Hurley <peter@hurleysoftware.com> Cc: Jiri Slaby <jslaby@suse.com> Cc: Robin Murphy <robin.murphy@arm.com> Cc: "Nair, Jayachandran" <Jayachandran.Nair@cavium.com> Cc: linux-serial@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org> Reported-by: Sudeep Holla <sudeep.holla@arm.com> Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Signed-off-by: Petr Mladek <pmladek@suse.com>
-rw-r--r--kernel/printk/printk.c46
1 files changed, 36 insertions, 10 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 82927ca04849..06051926dfde 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -266,6 +266,7 @@ static struct console *exclusive_console;
266#define MAX_CMDLINECONSOLES 8 266#define MAX_CMDLINECONSOLES 8
267 267
268static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES]; 268static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
269static int console_cmdline_cnt;
269 270
270static int preferred_console = -1; 271static int preferred_console = -1;
271int console_set_on_cmdline; 272int console_set_on_cmdline;
@@ -1902,12 +1903,25 @@ static int __add_preferred_console(char *name, int idx, char *options,
1902 * See if this tty is not yet registered, and 1903 * See if this tty is not yet registered, and
1903 * if we have a slot free. 1904 * if we have a slot free.
1904 */ 1905 */
1905 for (i = 0, c = console_cmdline; 1906 for (i = 0, c = console_cmdline; i < console_cmdline_cnt; i++, c++) {
1906 i < MAX_CMDLINECONSOLES && c->name[0];
1907 i++, c++) {
1908 if (strcmp(c->name, name) == 0 && c->index == idx) { 1907 if (strcmp(c->name, name) == 0 && c->index == idx) {
1909 if (!brl_options) 1908 if (brl_options)
1910 preferred_console = i; 1909 return 0;
1910
1911 /*
1912 * Maintain an invariant that will help to find if
1913 * the matching console is preferred, see
1914 * register_console():
1915 *
1916 * The last non-braille console is always
1917 * the preferred one.
1918 */
1919 if (i != console_cmdline_cnt - 1)
1920 swap(console_cmdline[i],
1921 console_cmdline[console_cmdline_cnt - 1]);
1922
1923 preferred_console = console_cmdline_cnt - 1;
1924
1911 return 0; 1925 return 0;
1912 } 1926 }
1913 } 1927 }
@@ -1920,6 +1934,7 @@ static int __add_preferred_console(char *name, int idx, char *options,
1920 braille_set_options(c, brl_options); 1934 braille_set_options(c, brl_options);
1921 1935
1922 c->index = idx; 1936 c->index = idx;
1937 console_cmdline_cnt++;
1923 return 0; 1938 return 0;
1924} 1939}
1925/* 1940/*
@@ -2459,12 +2474,23 @@ void register_console(struct console *newcon)
2459 } 2474 }
2460 2475
2461 /* 2476 /*
2462 * See if this console matches one we selected on 2477 * See if this console matches one we selected on the command line.
2463 * the command line. 2478 *
2479 * There may be several entries in the console_cmdline array matching
2480 * with the same console, one with newcon->match(), another by
2481 * name/index:
2482 *
2483 * pl011,mmio,0x87e024000000,115200 -- added from SPCR
2484 * ttyAMA0 -- added from command line
2485 *
2486 * Traverse the console_cmdline array in reverse order to be
2487 * sure that if this console is preferred then it will be the first
2488 * matching entry. We use the invariant that is maintained in
2489 * __add_preferred_console().
2464 */ 2490 */
2465 for (i = 0, c = console_cmdline; 2491 for (i = console_cmdline_cnt - 1; i >= 0; i--) {
2466 i < MAX_CMDLINECONSOLES && c->name[0]; 2492 c = console_cmdline + i;
2467 i++, c++) { 2493
2468 if (!newcon->match || 2494 if (!newcon->match ||
2469 newcon->match(newcon, c->name, c->index, c->options) != 0) { 2495 newcon->match(newcon, c->name, c->index, c->options) != 0) {
2470 /* default matching */ 2496 /* default matching */