The uart_open() function may call uart_close() with a 'serial_port' structure with an invalid member 'fd' if the port was not opened successfully. The call to uart_close() was kept for consistency with the rest of the function because uart_close() is also in charge of freeing 'serial_port'.