From 7a3d03c82d866225d83e1935633442fd7170afcc Mon Sep 17 00:00:00 2001 From: Yuan Liu Date: Thu, 2 Aug 2018 17:43:07 +0800 Subject: [PATCH] dm: uart: fix acrn-dm crash issue when invoke uart_closetty function mevent is added only if uart backend fd refers TTY in uart_opentty. So we should only delete mevent if uart backend fd refers TTY in uart_closetty. This issue can be reproduced by below steps 1) acrnd starts UOS 2) run poweroff command in UOS 3) crash happens Signed-off-by: Yuan Liu Acked-by: Yin Fengwei --- devicemodel/hw/uart_core.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/devicemodel/hw/uart_core.c b/devicemodel/hw/uart_core.c index b666503fb..33da09c40 100644 --- a/devicemodel/hw/uart_core.c +++ b/devicemodel/hw/uart_core.c @@ -275,12 +275,15 @@ uart_opentty(struct uart_vdev *uart) static void uart_closetty(struct uart_vdev *uart) { - if (uart->tty.fd != STDIN_FILENO) - mevent_delete_close(uart->mev); - else - mevent_delete(uart->mev); + if (isatty(uart->tty.fd)) { + if (uart->tty.fd != STDIN_FILENO) + mevent_delete_close(uart->mev); + else + mevent_delete(uart->mev); + + uart->mev = 0; + } - uart->mev = 0; ttyclose(); }