From patchwork Mon Jun 27 14:44:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 641084 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rdXQy2g2Vz9sBR for ; Tue, 28 Jun 2016 01:09:30 +1000 (AEST) Received: from localhost ([::1]:59221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHYAC-0006LS-9H for incoming@patchwork.ozlabs.org; Mon, 27 Jun 2016 11:09:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHXn3-00032b-VD for qemu-devel@nongnu.org; Mon, 27 Jun 2016 10:45:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHXmx-0008B0-UV for qemu-devel@nongnu.org; Mon, 27 Jun 2016 10:45:33 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:57999) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHXmx-000844-NO for qemu-devel@nongnu.org; Mon, 27 Jun 2016 10:45:27 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1bHXmi-0005RZ-VS for qemu-devel@nongnu.org; Mon, 27 Jun 2016 15:45:12 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 27 Jun 2016 15:44:54 +0100 Message-Id: <1467038710-24307-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467038710-24307-1-git-send-email-peter.maydell@linaro.org> References: <1467038710-24307-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 02/18] cadence_uart: Protect against transmit errors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alistair Francis 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 Message-id: 667e5dc534d33338fcfc2471e5aa32fe7cbd13dc.1466546703.git.alistair.francis@xilinx.com Reviewed-by: Peter Maydell Signed-off-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,