Skip to content

Commit dc05fff

Browse files
yliu80wenlingz
authored andcommitted
dm: uart: fix acrn-dm crash issue
This patch resolves acrn-dm crash issue when acrnd boots up the acrn-dm. The rootcause is mevent_enable and mevent_disable have NULL pointer as its parameter if uart backend is not tty capable, so add check code for the uart backend before invoking mevent_enable and mevent_disable. The issue can be reproduced when acrnd boots up the acrn-dm. Tracked-On: #1466 Signed-off-by: Yuan Liu <yuan1.liu@intel.com> Reviewed-by: Tomas Winkler <tomas.winkler@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
1 parent e7b63ae commit dc05fff

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

devicemodel/hw/uart_core.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,10 @@ rxfifo_reset(struct uart_vdev *uart, int size)
188188
* Enable mevent to trigger when new characters are available
189189
* on the tty fd.
190190
*/
191-
error = mevent_enable(uart->mev);
192-
assert(error == 0);
191+
if (isatty(uart->tty.fd)) {
192+
error = mevent_enable(uart->mev);
193+
assert(error == 0);
194+
}
193195
}
194196
}
195197

@@ -219,8 +221,10 @@ rxfifo_putchar(struct uart_vdev *uart, uint8_t ch)
219221
/*
220222
* Disable mevent callback if the FIFO is full.
221223
*/
222-
error = mevent_disable(uart->mev);
223-
assert(error == 0);
224+
if (isatty(uart->tty.fd)) {
225+
error = mevent_disable(uart->mev);
226+
assert(error == 0);
227+
}
224228
}
225229
}
226230
return 0;
@@ -243,7 +247,7 @@ rxfifo_getchar(struct uart_vdev *uart)
243247
fifo->rindex = (fifo->rindex + 1) % fifo->size;
244248
fifo->num--;
245249
if (wasfull) {
246-
if (uart->tty.opened) {
250+
if (uart->tty.opened && isatty(uart->tty.fd)) {
247251
error = mevent_enable(uart->mev);
248252
assert(error == 0);
249253
}

0 commit comments

Comments
 (0)