From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFToD-0001Jp-9f for qemu-devel@nongnu.org; Tue, 21 Jun 2016 18:06:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFTo8-0005PS-8T for qemu-devel@nongnu.org; Tue, 21 Jun 2016 18:06:13 -0400 Received: from mail-bl2nam02on0041.outbound.protection.outlook.com ([104.47.38.41]:61568 helo=NAM02-BL2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFTo8-0005Ow-0B for qemu-devel@nongnu.org; Tue, 21 Jun 2016 18:06:08 -0400 From: Alistair Francis Date: Tue, 21 Jun 2016 15:05:52 -0700 Message-ID: <667e5dc534d33338fcfc2471e5aa32fe7cbd13dc.1466546703.git.alistair.francis@xilinx.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v1 1/1] cadence_uart: Protect against transmit errors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: alistair.francis@xilinx.com, crosthwaitepeter@gmail.com, peter.maydell@linaro.org, edgar.iglesias@xilinx.com, edgar.iglesias@gmail.com 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 Reported-by: Peter Maydell --- hw/char/cadence_uart.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c index c856fc3..844542f 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, -- 2.7.4