From 7b6dfedec422a42d3d292fe39d7ccb00a2385dc5 Mon Sep 17 00:00:00 2001 From: Qing Chang Date: Tue, 19 Mar 2019 12:23:31 -0500 Subject: [PATCH] printk: Keep boot console on if enabled Without this change, the boot console has strong assumption of the state of the "real" console, so when PM kicks in during early boot stage, resources (l(CR) clocks, GPIOs, etc) for the boot console may be turned off if the "real" console sharing these resources is not enabled, which will lead to malfuntion of boot console. Change-Id: I19a58d76c99e0fb7bff0d9dc06a2b0f9066063e2 Signed-off-by: Qing Chang Reviewed-on: https://gerrit.mot.com/1472630 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Qing Chang Submit-Approved: Jira Key Signed-off-by: Qing Chang Reviewed-on: https://gerrit.mot.com/1474157 Reviewed-on: https://gerrit.mot.com/1509725 Reviewed-by: Wang Wang --- kernel/printk/printk.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index b5f08345843c..a44e1e5f67c9 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2635,14 +2635,26 @@ void register_console(struct console *newcon) struct console *bcon = NULL; struct console_cmdline *c; static bool has_preferred; + bool duplicated = false; if (console_drivers) - for_each_console(bcon) + for_each_console(bcon) { if (WARN(bcon == newcon, "console '%s%d' already registered\n", bcon->name, bcon->index)) return; + if ((bcon->flags & CON_BOOT) && bcon->match && + !bcon->match(bcon, newcon->name, + newcon->index, NULL)) { + pr_info("Duplicated console '%s%d' & '%s%d'\n", + bcon->name, bcon->index, + newcon->name, newcon->index); + + duplicated = true; + } + } + /* * before we register a new CON_BOOT console, make sure we don't * already have a valid console @@ -2717,8 +2729,18 @@ void register_console(struct console *newcon) break; } - if (!(newcon->flags & CON_ENABLED)) + if (!(newcon->flags & CON_ENABLED)) { + if (duplicated) { + if (newcon->index < 0) + newcon->index = 0; + + if (newcon->setup && newcon->setup(newcon, NULL)) + pr_err("Failed to set up duplicated console " + "'%s%d'\n", newcon->name, newcon->index); + } + return; + } /* * If we have a bootconsole, and are switching to a real console,