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

From: Biju Das

Date: Wed Apr 08 2026 - 12:07:09 EST


Hi Geert,

Thanks for the feedback.

> -----Original Message-----
> From: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
> Sent: 08 April 2026 16:39
> Subject: Re: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault
>
> Hi Biju,
>
> On Wed, 8 Apr 2026 at 16:21, 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.
> >
> > Signed-off-by: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
>
> Thanks for your patch!
>
> > --- 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);
>
> Nice catches!
>
> >
> > /* byte size and parity */
> > bits = tty_get_frame_size(termios->c_cflag);
>
> I think there's another one out of context, which can even trigger with baud == 75:
>

Will add a check, if (baud > 99)

Cheers,
Biju

> s->rx_frame = (10000 * bits) / (baud / 100);
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx
>
> In personal conversations with technical people, I call myself a hacker. But when I'm talking to
> journalists I just say "programmer" or something like that.
> -- Linus Torvalds