diff --git a/devicemodel/hw/pci/lpc.c b/devicemodel/hw/pci/lpc.c index dc50a092b..3cb0da0a4 100644 --- a/devicemodel/hw/pci/lpc.c +++ b/devicemodel/hw/pci/lpc.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "vmmapi.h" #include "acpi.h" @@ -214,7 +215,12 @@ lpc_init(struct vmctx *ctx) goto init_failed; } - if (uart_set_backend(lpc_uart->uart, lpc_uart->opts) != 0) { + error = uart_set_backend(lpc_uart->uart, lpc_uart->opts); + /* + * Continue to initialize LPC UART device if opts is invalid, + * and the data will be dropped by uart_write in UART DM. + */ + if (error && error != -EINVAL) { fprintf(stderr, "Unable to initialize backend '%s' " "for LPC device %s\n", lpc_uart->opts, name); uart_deinit(lpc_uart->uart); diff --git a/devicemodel/hw/pci/uart.c b/devicemodel/hw/pci/uart.c index 1376d9480..a8633198f 100644 --- a/devicemodel/hw/pci/uart.c +++ b/devicemodel/hw/pci/uart.c @@ -27,6 +27,7 @@ */ #include +#include #include "pci_core.h" #include "uart_core.h" @@ -82,6 +83,7 @@ static int pci_uart_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) { struct uart_vdev *uart; + int ret; pci_emul_alloc_bar(dev, 0, PCIBAR_IO, UART_IO_BAR_SIZE); pci_lintr_request(dev); @@ -94,7 +96,8 @@ pci_uart_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) uart = uart_init(pci_uart_intr_assert, pci_uart_intr_deassert, dev); dev->arg = uart; - if (uart_set_backend(uart, opts) != 0) { + ret = uart_set_backend(uart, opts); + if (ret && ret != -EINVAL) { fprintf(stderr, "Unable to initialize backend '%s' for " "pci uart at %d:%d\n", opts, dev->slot, dev->func); return -1; diff --git a/devicemodel/hw/uart_core.c b/devicemodel/hw/uart_core.c index 02dc297a0..b666503fb 100644 --- a/devicemodel/hw/uart_core.c +++ b/devicemodel/hw/uart_core.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "types.h" #include "mevent.h" @@ -679,7 +680,7 @@ uart_set_backend(struct uart_vdev *uart, const char *opts) retval = -1; if (opts == NULL) - return 0; + return -EINVAL; if (strcmp("stdio", opts) == 0) { if (!stdio_in_use) { @@ -692,6 +693,9 @@ uart_set_backend(struct uart_vdev *uart, const char *opts) retval = 0; } + if (retval) + return -EINVAL; + /* Make the backend file descriptor non-blocking */ if (retval == 0) retval = fcntl(uart->tty.fd, F_SETFL, O_NONBLOCK);