From patchwork Thu Jun 23 17:22:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 639787 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 3rb7bh2fmlz9sdm for ; Fri, 24 Jun 2016 03:23:44 +1000 (AEST) Received: from localhost ([::1]:38257 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG8Lu-0004KT-3B for incoming@patchwork.ozlabs.org; Thu, 23 Jun 2016 13:23:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG8Kj-0003Im-U5 for qemu-devel@nongnu.org; Thu, 23 Jun 2016 13:22:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bG8Kd-0006UD-NN for qemu-devel@nongnu.org; Thu, 23 Jun 2016 13:22:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48996) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG8Kd-0006U5-Dq for qemu-devel@nongnu.org; Thu, 23 Jun 2016 13:22:23 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F22FE81F07 for ; Thu, 23 Jun 2016 17:22:22 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-75.ams2.redhat.com [10.36.112.75]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5NHMJHB014780; Thu, 23 Jun 2016 13:22:21 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 23 Jun 2016 19:22:14 +0200 Message-Id: <1466702539-17607-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1466702539-17607-1-git-send-email-pbonzini@redhat.com> References: <1466702539-17607-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 23 Jun 2016 17:22:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/6] serial: make tsr_retry unsigned 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: , Cc: dgilbert@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It can never become negative; reflect this in the type of the field and simplify the conditions. Tested-by: Bret Ketchum Signed-off-by: Paolo Bonzini --- hw/char/serial.c | 12 ++++++++---- include/hw/char/serial.h | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/char/serial.c b/hw/char/serial.c index 6d815b5..e65e9e0 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -229,7 +229,7 @@ static gboolean serial_xmit(GIOChannel *chan, GIOCondition cond, void *opaque) do { assert(!(s->lsr & UART_LSR_TEMT)); - if (s->tsr_retry <= 0) { + if (s->tsr_retry == 0) { assert(!(s->lsr & UART_LSR_THRE)); if (s->fcr & UART_FCR_FE) { @@ -252,7 +252,7 @@ static gboolean serial_xmit(GIOChannel *chan, GIOCondition cond, void *opaque) /* 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 >= 0 && s->tsr_retry < MAX_XMIT_RETRY && + if (s->tsr_retry < MAX_XMIT_RETRY && qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP, serial_xmit, s) > 0) { s->tsr_retry++; @@ -330,7 +330,7 @@ static void serial_ioport_write(void *opaque, hwaddr addr, uint64_t val, s->lsr &= ~UART_LSR_THRE; s->lsr &= ~UART_LSR_TEMT; serial_update_irq(s); - if (s->tsr_retry <= 0) { + if (s->tsr_retry == 0) { serial_xmit(NULL, G_IO_OUT, s); } } @@ -639,6 +639,10 @@ static int serial_post_load(void *opaque, int version_id) if (s->thr_ipending == -1) { s->thr_ipending = ((s->iir & UART_IIR_ID) == UART_IIR_THRI); } + if (s->tsr_retry > MAX_XMIT_RETRY) { + s->tsr_retry = MAX_XMIT_RETRY; + } + s->last_break_enable = (s->lcr >> 6) & 1; /* Initialize fcr via setter to perform essential side-effects */ serial_write_fcr(s, s->fcr_vmstate); @@ -685,7 +689,7 @@ static const VMStateDescription vmstate_serial_tsr = { .minimum_version_id = 1, .needed = serial_tsr_needed, .fields = (VMStateField[]) { - VMSTATE_INT32(tsr_retry, SerialState), + VMSTATE_UINT32(tsr_retry, SerialState), VMSTATE_UINT8(thr, SerialState), VMSTATE_UINT8(tsr, SerialState), VMSTATE_END_OF_LIST() diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index 15beb6b..6a322eb 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -55,7 +55,7 @@ struct SerialState { int last_break_enable; int it_shift; int baudbase; - int tsr_retry; + uint32_t tsr_retry; uint32_t wakeup; /* Time when the last byte was successfully sent out of the tsr */