From 2849932c4853ba36edafb5ae16c67e5976d95372 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 31 Jul 2015 11:19:19 +0100 Subject: [serial] Check for UART existence in uart_select() Check for existence of the UART in uart_select(), not just in uart_init(). This allows uart_select() to refuse to set a non-working address in uart->base, which in turns means that the serial console code will not attempt to use a non-existent UART. Reported-by: Torgeir Wulfsberg Reported-by: Ján ONDREJ (SAL) Signed-off-by: Michael Brown --- src/arch/x86/core/x86_uart.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/arch') diff --git a/src/arch/x86/core/x86_uart.c b/src/arch/x86/core/x86_uart.c index 7c3a01d66..e455775bf 100644 --- a/src/arch/x86/core/x86_uart.c +++ b/src/arch/x86/core/x86_uart.c @@ -48,15 +48,22 @@ static uint16_t uart_base[] = { * @ret rc Return status code */ int uart_select ( struct uart *uart, unsigned int port ) { - - /* Clear UART base */ - uart->base = NULL; + int rc; /* Set new UART base */ - if ( port < ( sizeof ( uart_base ) / sizeof ( uart_base[0] ) ) ) { - uart->base = ( ( void * ) ( intptr_t ) uart_base[port] ); - return 0; - } else { - return -ENODEV; + if ( port >= ( sizeof ( uart_base ) / sizeof ( uart_base[0] ) ) ) { + rc = -ENODEV; + goto err; } + uart->base = ( ( void * ) ( intptr_t ) uart_base[port] ); + + /* Check that UART exists */ + if ( ( rc = uart_exists ( uart ) ) != 0 ) + goto err; + + return 0; + + err: + uart->base = NULL; + return rc; } -- cgit v1.2.3-55-g7522