From d1949353e5f57678f227b0b283cb63f367174e96 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Thu, 14 Jan 2021 13:43:15 -0700 Subject: [PATCH] uart: Improve console specification parsing Print warning when we can't parse a console specification (this may not appear on the console, but will appear in dmesg). Also, accept key:value and key=value. There's no reason not to and it makes this more forgiving of mistakes. Reviewed by: rpokala@ Differential Revision: https://reviews.freebsd.org/D28168 --- sys/dev/uart/uart_subr.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/sys/dev/uart/uart_subr.c b/sys/dev/uart/uart_subr.c index 96d7735ea0ed..e6dec58d7705 100644 --- a/sys/dev/uart/uart_subr.c +++ b/sys/dev/uart/uart_subr.c @@ -172,7 +172,7 @@ uart_parse_tag(const char **p) out: *p += 2; - if ((*p)[0] != ':') + if ((*p)[0] != ':' && (*p)[0] != '=') return (-1); (*p)++; return (tag); @@ -283,25 +283,22 @@ uart_getenv(int devtype, struct uart_devinfo *di, struct uart_class *class) di->bas.rclk = uart_parse_long(&spec); break; default: - freeenv(cp); - return (EINVAL); + goto inval; } if (*spec == '\0') break; - if (*spec != ',') { - freeenv(cp); - return (EINVAL); - } + if (*spec != ',') + goto inval; spec++; } - freeenv(cp); /* * If we still have an invalid address, the specification must be * missing an I/O port or memory address. We don't like that. */ if (addr == ~0U) - return (EINVAL); + goto inval; + freeenv(cp); /* * Accept only the well-known baudrates. Any invalid baudrate @@ -327,4 +324,8 @@ uart_getenv(int devtype, struct uart_devinfo *di, struct uart_class *class) error = bus_space_map(di->bas.bst, addr, uart_getrange(class), 0, &di->bas.bsh); return (error); +inval: + printf("warning: bad uart specification: %s\n", cp); + freeenv(cp); + return (EINVAL); }