Commit f8c3686c authored by Michael Walle's avatar Michael Walle Committed by Greg Kroah-Hartman

serial: earlycon: prefer EARLYCON_DECLARE() variant

If a driver exposes early consoles with EARLYCON_DECLARE() and
OF_EARLYCON_DECLARE(), pefer the non-OF variant if the user specifies it
by
  earlycon=<driver>,<options>

The rationale behind this is that some drivers register multiple setup
functions under the same driver name. Eg.

OF_EARLYCON_DECLARE(lpuart, "fsl,vf610-lpuart", lpuart_early_console_setup);
OF_EARLYCON_DECLARE(lpuart32, "fsl,ls1021a-lpuart", lpuart32_early_console_setup);
OF_EARLYCON_DECLARE(lpuart32, "fsl,imx7ulp-lpuart", lpuart32_imx_early_console_setup);
EARLYCON_DECLARE(lpuart, lpuart_early_console_setup);
EARLYCON_DECLARE(lpuart32, lpuart32_early_console_setup);

It depends on the order of the entries which console_setup() actually
gets called. To make things worse, I guess it also depends on the
compiler how these are ordered. Thus always prefer the EARLYCON_DECLARE()
ones.
Signed-off-by: default avatarMichael Walle <michael@walle.cc>
Link: https://lore.kernel.org/r/20200220174607.24285-1-michael@walle.ccSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 4f5f5887
...@@ -170,6 +170,7 @@ static int __init register_earlycon(char *buf, const struct earlycon_id *match) ...@@ -170,6 +170,7 @@ static int __init register_earlycon(char *buf, const struct earlycon_id *match)
int __init setup_earlycon(char *buf) int __init setup_earlycon(char *buf)
{ {
const struct earlycon_id **p_match; const struct earlycon_id **p_match;
bool empty_compatible = true;
if (!buf || !buf[0]) if (!buf || !buf[0])
return -EINVAL; return -EINVAL;
...@@ -177,6 +178,7 @@ int __init setup_earlycon(char *buf) ...@@ -177,6 +178,7 @@ int __init setup_earlycon(char *buf)
if (early_con.flags & CON_ENABLED) if (early_con.flags & CON_ENABLED)
return -EALREADY; return -EALREADY;
again:
for (p_match = __earlycon_table; p_match < __earlycon_table_end; for (p_match = __earlycon_table; p_match < __earlycon_table_end;
p_match++) { p_match++) {
const struct earlycon_id *match = *p_match; const struct earlycon_id *match = *p_match;
...@@ -185,6 +187,10 @@ int __init setup_earlycon(char *buf) ...@@ -185,6 +187,10 @@ int __init setup_earlycon(char *buf)
if (strncmp(buf, match->name, len)) if (strncmp(buf, match->name, len))
continue; continue;
/* prefer entries with empty compatible */
if (empty_compatible && *match->compatible)
continue;
if (buf[len]) { if (buf[len]) {
if (buf[len] != ',') if (buf[len] != ',')
continue; continue;
...@@ -195,6 +201,11 @@ int __init setup_earlycon(char *buf) ...@@ -195,6 +201,11 @@ int __init setup_earlycon(char *buf)
return register_earlycon(buf, match); return register_earlycon(buf, match);
} }
if (empty_compatible) {
empty_compatible = false;
goto again;
}
return -ENOENT; return -ENOENT;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment