qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alistair Francis <alistair.francis@xilinx.com>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: alistair.francis@xilinx.com, alistair23@gmail.com,
	pjp@fedoraproject.org, psirt@huawei.com
Subject: [Qemu-devel] [PATCH v1 1/1] cadence_uart: Check baud rate generator and divider values on migration
Date: Fri, 4 Nov 2016 17:00:31 -0700	[thread overview]
Message-ID: <d30a50ca3497f2a909cd50f07413dd7250078e9d.1478303567.git.alistair.francis@xilinx.com> (raw)

The Cadence UART device emulator calculates speed by dividing the
baud rate by a 'baud rate generator' & 'baud rate divider' value.
The device specification defines these register values to be
non-zero and within certain limits. Checks were recently added when
writing to these registers but not when restoring from migration.

This patch adds checks when restoring from migration to avoid divide by
zero errors.

Reported-by: Huawei PSIRT <psirt@huawei.com>
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---

 hw/char/cadence_uart.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index def34cd..e3a6248 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -487,6 +487,19 @@ static int cadence_uart_post_load(void *opaque, int version_id)
 {
     CadenceUARTState *s = opaque;
 
+    /* Ensure these two aren't invalid numbers */
+    if (s->r[R_BRGR] <= 1) {
+        /* Value is invalid, reset it */
+        s->r[R_BRGR] = 0x0000028B;
+    }
+    if (s->r[R_BDIV] <= 3) {
+        /* Value is invalid, reset it */
+        s->r[R_BDIV] = 0x0000000F;
+    }
+
+    s->r[R_BRGR] = s->r[R_BRGR] & 0xFFFF;
+    s->r[R_BDIV] = s->r[R_BDIV] & 0xFF;
+
     uart_parameters_setup(s);
     uart_update_status(s);
     return 0;
-- 
2.7.4

             reply	other threads:[~2016-11-05  0:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-05  0:00 Alistair Francis [this message]
2016-11-05 13:51 ` [Qemu-devel] [PATCH v1 1/1] cadence_uart: Check baud rate generator and divider values on migration Peter Maydell
2016-11-07 21:53   ` Alistair Francis
2016-11-07 22:13     ` Peter Maydell
2016-11-07 22:43       ` Alistair Francis

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=d30a50ca3497f2a909cd50f07413dd7250078e9d.1478303567.git.alistair.francis@xilinx.com \
    --to=alistair.francis@xilinx.com \
    --cc=alistair23@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=pjp@fedoraproject.org \
    --cc=psirt@huawei.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).