Re: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault

From: Hugo Villeneuve

Date: Wed Apr 08 2026 - 12:48:56 EST


Hi Biju,

On Wed, 8 Apr 2026 15:20:58 +0100
Biju <biju.das.au@xxxxxxxxx> wrote:

> From: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
>
> uart_update_timeout() computes a timeout value by dividing by the baud
> rate. If baud is zero — which can occur when the hardware returns an
> unsupported or invalid rate — this results in a divide-by-zero fault.

baud is returned by uart_get_baud_rate(), so this is not returned
by the hardware?


>
> Signed-off-by: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>

Missing Fixes tag?


> ---
> v2:
> * New patch
> ---
> drivers/tty/serial/rsci.c | 3 ++-
> drivers/tty/serial/sh-sci.c | 3 ++-
> 2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/tty/serial/rsci.c b/drivers/tty/serial/rsci.c
> index b00c9e385169..a0858bab0822 100644
> --- a/drivers/tty/serial/rsci.c
> +++ b/drivers/tty/serial/rsci.c
> @@ -286,7 +286,8 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios,
> sci_port_enable(s);
> uart_port_lock_irqsave(port, &flags);
>
> - uart_update_timeout(port, termios->c_cflag, baud);
> + if (baud)
> + uart_update_timeout(port, termios->c_cflag, baud);
>
> rsci_serial_out(port, CCR0, ccr0_val);
>
> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> index 6c819b6b2425..429e89106ee3 100644
> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -2805,7 +2805,8 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
>
> sci_reset(port);
>
> - uart_update_timeout(port, termios->c_cflag, baud);
> + if (baud)
> + uart_update_timeout(port, termios->c_cflag, baud);

After this patch, have you re-tested if having baud = 0 produces any
other errors? A litle bit later in the same function, there is this
code:

/* Calculate delay for 2 DMA buffers (4 FIFO). */
s->rx_frame = (10000 * bits) / (baud / 100);

Does this trigger a division by zero fault?

There is also this:

if ((srr + 1 == 5) &&
(s->type == PORT_SCIFA || s->type == PORT_SCIFB)) {
...
udelay(DIV_ROUND_UP(10 * 1000000, baud));

Can this also trigger a division by zero fault?


>
> /* byte size and parity */
> bits = tty_get_frame_size(termios->c_cflag);
> --
> 2.43.0
>
>


--
Hugo Villeneuve