qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: dgilbert@redhat.com, bcketchum@gmail.com
Subject: [Qemu-devel] [PATCH 1/6] serial: make tsr_retry unsigned
Date: Mon, 20 Jun 2016 16:29:00 +0200	[thread overview]
Message-ID: <1466432945-28682-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1466432945-28682-1-git-send-email-pbonzini@redhat.com>

It can never become negative; reflect this in the type of the field
and simplify the conditions.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 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 */
-- 
2.5.5

  reply	other threads:[~2016-06-20 14:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-20 14:28 [Qemu-devel] [PATCH 0/6] serial: flow control fixes Paolo Bonzini
2016-06-20 14:29 ` Paolo Bonzini [this message]
2016-06-22 14:44   ` [Qemu-devel] [PATCH 1/6] serial: make tsr_retry unsigned Dr. David Alan Gilbert
2016-06-20 14:29 ` [Qemu-devel] [PATCH 2/6] serial: reinstate watch after migration Paolo Bonzini
2016-06-22 15:05   ` Dr. David Alan Gilbert
2016-06-22 15:11     ` Paolo Bonzini
2016-06-22 15:41       ` Dr. David Alan Gilbert
2016-06-20 14:29 ` [Qemu-devel] [PATCH 3/6] serial: separate serial_xmit and serial_watch_cb Paolo Bonzini
2016-06-22 15:09   ` Dr. David Alan Gilbert
2016-06-22 15:14     ` Paolo Bonzini
2016-06-20 14:29 ` [Qemu-devel] [PATCH 4/6] serial: simplify tsr_retry reset Paolo Bonzini
2016-06-22 15:12   ` Dr. David Alan Gilbert
2016-06-20 14:29 ` [Qemu-devel] [PATCH 5/6] char: change qemu_chr_fe_add_watch to return unsigned Paolo Bonzini
2016-06-22 15:22   ` Dr. David Alan Gilbert
2016-06-20 14:29 ` [Qemu-devel] [PATCH 6/6] serial: remove watch on reset Paolo Bonzini
2016-06-22 14:04   ` Bret Ketchum
2016-06-22 15:38   ` Dr. David Alan Gilbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1466432945-28682-2-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=bcketchum@gmail.com \
    --cc=dgilbert@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).