From a5121e95e91a1fb71e60de8d1575c3b8fb5d370e Mon Sep 17 00:00:00 2001 From: Yuan Liu Date: Mon, 6 Aug 2018 10:11:25 +0800 Subject: [PATCH] dm: uart: add state check of backend tty before uart_closetty This patch resolves one arcn-dm crash issue when rebooting UOS. The rootcause is that uart releases unopened backend tty. One reproduced case is that the board does not support IOC but IOC feature is enabled in the acrn-dm. After rebooting UOS, crash will happen. NOTE: This issue is not related to IOC, it also can be reproduced with NON-IOC scenario. Just set one invalid PTY to the lpc, then this issue should be reproduced. We need re-visit the whole policy for such scenario in future. Signed-off-by: Yuan Liu Reviewed-by: Yin Fengwei Acked-by: Yu Wang --- devicemodel/hw/uart_core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/devicemodel/hw/uart_core.c b/devicemodel/hw/uart_core.c index 33da09c40..1b67d2979 100644 --- a/devicemodel/hw/uart_core.c +++ b/devicemodel/hw/uart_core.c @@ -715,6 +715,16 @@ uart_release_backend(struct uart_vdev *uart, const char *opts) if (opts == NULL) return; + /* + * By current design, for the invalid PTY parameters, the virtual uarts + * are still expose to UOS but all data be dropped by backend service. + * The uart backend is not setup for this case, so don't try to release + * the uart backend in here. + * TODO: need re-visit the whole policy for such scenario in future. + */ + if (!uart->tty.opened) + return; + uart_closetty(uart); if (strcmp("stdio", opts) == 0) { stdio_in_use = false;