Skip to content

Commit

Permalink
serial: remove watch on reset
Browse files Browse the repository at this point in the history
Otherwise, this can cause serial_xmit to be entered with LSR.TEMT=0,
which is invalid and causes an assertion failure.

Reported-by: Bret Ketchum <bcketchum@gmail.com>
Tested-by: Bret Ketchum <bcketchum@gmail.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
bonzini committed Jun 29, 2016
1 parent 6f1de6b commit a1df76d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions hw/char/serial.c
Expand Up @@ -228,6 +228,7 @@ static gboolean serial_watch_cb(GIOChannel *chan, GIOCondition cond,
void *opaque)
{
SerialState *s = opaque;
s->watch_tag = 0;
serial_xmit(s);
return FALSE;
}
Expand Down Expand Up @@ -258,10 +259,12 @@ static void serial_xmit(SerialState *s)
if (s->mcr & UART_MCR_LOOP) {
/* in loopback mode, say that we just received a char */
serial_receive1(s, &s->tsr, 1);
} else if (qemu_chr_fe_write(s->chr, &s->tsr, 1) != 1) {
if (s->tsr_retry < MAX_XMIT_RETRY &&
qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP,
serial_watch_cb, s) > 0) {
} else if (qemu_chr_fe_write(s->chr, &s->tsr, 1) != 1 &&
s->tsr_retry < MAX_XMIT_RETRY) {
assert(s->watch_tag == 0);
s->watch_tag = qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP,
serial_watch_cb, s);
if (s->watch_tag > 0) {
s->tsr_retry++;
return;
}
Expand Down Expand Up @@ -821,6 +824,11 @@ static void serial_reset(void *opaque)
{
SerialState *s = opaque;

if (s->watch_tag > 0) {
g_source_remove(s->watch_tag);
s->watch_tag = 0;
}

s->rbr = 0;
s->ier = 0;
s->iir = UART_IIR_NO_INT;
Expand Down
1 change: 1 addition & 0 deletions include/hw/char/serial.h
Expand Up @@ -56,6 +56,7 @@ struct SerialState {
int it_shift;
int baudbase;
uint32_t tsr_retry;
guint watch_tag;
uint32_t wakeup;

/* Time when the last byte was successfully sent out of the tsr */
Expand Down

0 comments on commit a1df76d

Please sign in to comment.