From patchwork Mon Jun 20 14:29:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9187813 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8875C601C0 for ; Mon, 20 Jun 2016 15:26:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 751812793A for ; Mon, 20 Jun 2016 15:26:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 684C2279E0; Mon, 20 Jun 2016 15:26:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C31532793A for ; Mon, 20 Jun 2016 15:26:24 +0000 (UTC) Received: from localhost ([::1]:44340 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF15i-0003Bh-Ug for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jun 2016 11:26:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54012) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0CV-000888-M3 for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bF0CL-0003Ap-Jn for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:18 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33781) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0CL-0003Aj-Cn for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:09 -0400 Received: by mail-wm0-x242.google.com with SMTP id r201so14551509wme.0 for ; Mon, 20 Jun 2016 07:29:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Q4VSal6bjbrElGSqB5A9p5Lg1zSZ1bLbQWjkuA5AGb4=; b=yuYEmrIBoM7jwCsi8Ir7o9vKZwXf5homaYkmyhSxHn9Y4u/iRqsGr86ovFKoNKjpVa L7g/Y9luu2IvcFxTzoI+OJMB8vCK4LBkRyfARCxFAeTcjenrh5FHALZghkxadsSNKV8o MKBLilYEtnKiKxrNIA0BVvetIBrqn4SFIx4PfnROeSzfefzEOL0ua7Nirauh9eSeI59i YCxZYXcOm00gf88PO8XJqOsUILedQ2JAFCCgTqFy4Rvs2aoGAaOzl+rbKqGz32J0GRwE 9znuMZEZnxOqY86ohBUkG+uZeTtObQ0GW1qg5A+oR02Npy3UwN1qDuGcI20qlPCj8BCV tzcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Q4VSal6bjbrElGSqB5A9p5Lg1zSZ1bLbQWjkuA5AGb4=; b=YroTuYEQsDqF47m7q7lCuBl1uCvYowzNadXiIw+ZB9OYEyEaL0Axuwidy81+08GCyx 1GflOtW0DTZcz4p9o76lOK82oygk5yBBJYSQBRWy6kFVmlNrNz9U1Kkq0cuhVVD1Xrhn YcKsBv5I212wX3x5Q8DMha/TgRD945I2L1U7+CxI7iu6W8Y7T/Ev6+42jAhpVC84Qd6/ 72832SapZKJMLgq55s7f4p1FOfPY/P9jgiVj2enBuYCOKLSpvHVyeYwS6/6vi3+EFfAz fNXZScMNDWWDYHcGuc6+DJuLWvtqtiieOqglsFuzYz9tPRGSrN4+iU4kvCxjUnNS3GBq BeJQ== X-Gm-Message-State: ALyK8tLLr8nFNQd9UM/cDDeGMMtMLMelhxh/HmEL12b3NFVrGqQA4KIWDUx/TPCVUX20Uw== X-Received: by 10.194.246.4 with SMTP id xs4mr5701565wjc.96.1466432948685; Mon, 20 Jun 2016 07:29:08 -0700 (PDT) Received: from donizetti.lan (94-39-188-118.adsl-ull.clienti.tiscali.it. [94.39.188.118]) by smtp.gmail.com with ESMTPSA id bb4sm24359892wjb.32.2016.06.20.07.29.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jun 2016 07:29:07 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 20 Jun 2016 16:29:00 +0200 Message-Id: <1466432945-28682-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1466432945-28682-1-git-send-email-pbonzini@redhat.com> References: <1466432945-28682-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PATCH 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: bcketchum@gmail.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP It can never become negative; reflect this in the type of the field and simplify the conditions. Signed-off-by: Paolo Bonzini Reviewed-by: Dr. David Alan Gilbert --- 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..ef90615 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; + unsigned tsr_retry; uint32_t wakeup; /* Time when the last byte was successfully sent out of the tsr */