[PATCH v3 1/3] serial: sh-sci: Avoid divide-by-zero fault
From: Biju
Date: Mon Apr 20 2026 - 11:52:12 EST
From: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
The expression (10000 * bits) / (baud / 100) can produce a divide-by-zero
if baud is less than 100, since integer division yields zero before the
outer divide occurs. Rewrite it as (10000 * bits) * 100 / baud, which is
algebraically equivalent but eliminates the intermediate division, making
a zero divisor impossible for any valid baud rate.
Signed-off-by: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
---
v3:
* New patch.
---
drivers/tty/serial/sh-sci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 6c819b6b2425..7473b26ce9cf 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2915,7 +2915,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
}
/* Calculate delay for 2 DMA buffers (4 FIFO). */
- s->rx_frame = (10000 * bits) / (baud / 100);
+ s->rx_frame = (10000 * bits) * 100 / baud;
#ifdef CONFIG_SERIAL_SH_SCI_DMA
s->rx_timeout = s->buf_len_rx * 2 * s->rx_frame;
#endif
--
2.43.0