Guard NANOSECONDS_PER_SECOND / baud with a zero check. The baud rate
can be zero when the NCO field is zero or the input clock is not yet
configured.

Fixes: a7d2d98c5944 ("hw/char: Initial commit of Ibex UART")
Fixes: 940aabb9f477 ("hw/char: Convert the Ibex UART to use the qdev Clock 
model")
Reported-by: Pavee Hui <[email protected]>
Signed-off-by: Marc-André Lureau <[email protected]>
---
 hw/char/ibex_uart.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c
index 26ed1aea140b..4c22fb4f58a8 100644
--- a/hw/char/ibex_uart.c
+++ b/hw/char/ibex_uart.c
@@ -395,7 +395,9 @@ static void ibex_uart_write(void *opaque, hwaddr addr,
         if (value & R_CTRL_NCO_MASK) {
             uint64_t baud = ibex_uart_get_baud(s);
 
-            s->char_tx_time = (NANOSECONDS_PER_SECOND / baud) * 10;
+            if (baud) {
+                s->char_tx_time = (NANOSECONDS_PER_SECOND / baud) * 10;
+            }
         }
         break;
     case R_STATUS:
@@ -455,7 +457,9 @@ static void ibex_uart_clk_update(void *opaque, ClockEvent 
event)
     /* recompute uart's speed on clock change */
     uint64_t baud = ibex_uart_get_baud(s);
 
-    s->char_tx_time = (NANOSECONDS_PER_SECOND / baud) * 10;
+    if (baud) {
+        s->char_tx_time = (NANOSECONDS_PER_SECOND / baud) * 10;
+    }
 }
 
 static void fifo_trigger_update(void *opaque)

-- 
2.56.0.rc0.29.g47ce80527c56


Reply via email to