summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorAlistair Francis <alistair.francis@xilinx.com>2016-06-27 15:37:32 +0100
committerPeter Maydell <peter.maydell@linaro.org>2016-06-27 15:37:32 +0100
commitf6cf41932edf260c2574346a08358ad2d20c357e (patch)
treeea257aec4bcf2176b603a84f2790ff268f967603 /hw
parent92b30c2f7d783e423f3d0093a14c88f4532c0de1 (diff)
downloadqemu-f6cf41932edf260c2574346a08358ad2d20c357e.tar.gz
qemu-f6cf41932edf260c2574346a08358ad2d20c357e.tar.bz2
qemu-f6cf41932edf260c2574346a08358ad2d20c357e.zip
cadence_uart: Protect against transmit errors
If qemu_chr_fe_write() returns an error (represented by a negative number) we should skip incrementing the count and initiating a memmove(). Signed-off-by: Alistair Francis <alistair.francis@xilinx.com> Reported-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 667e5dc534d33338fcfc2471e5aa32fe7cbd13dc.1466546703.git.alistair.francis@xilinx.com Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw')
-rw-r--r--hw/char/cadence_uart.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index c856fc30b2..844542fd5a 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -288,8 +288,11 @@ static gboolean cadence_uart_xmit(GIOChannel *chan, GIOCondition cond,
}
ret = qemu_chr_fe_write(s->chr, s->tx_fifo, s->tx_count);
- s->tx_count -= ret;
- memmove(s->tx_fifo, s->tx_fifo + ret, s->tx_count);
+
+ if (ret >= 0) {
+ s->tx_count -= ret;
+ memmove(s->tx_fifo, s->tx_fifo + ret, s->tx_count);
+ }
if (s->tx_count) {
int r = qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP,