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

From: Hugo Villeneuve

Date: Wed Apr 08 2026 - 14:17:55 EST


Hi Biju,

On Wed, 8 Apr 2026 17:25:19 +0000
Biju Das <biju.das.jz@xxxxxxxxxxxxxx> wrote:

> Hi Hugo,
>
> > -----Original Message-----
> > From: Hugo Villeneuve <hugo@xxxxxxxxxxx>
> > Sent: 08 April 2026 17:52
> > Subject: Re: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault
> >
> > Hi Biju,
> >
> > On Wed, 8 Apr 2026 16:35:44 +0000
> > Biju Das <biju.das.jz@xxxxxxxxxxxxxx> wrote:
> >
> > > Hi Hugo,
> > >
> > > Thanks for the feedback.
> > >
> > > > -----Original Message-----
> > > > From: Hugo Villeneuve <hugo@xxxxxxxxxxx>
> > > > Sent: 08 April 2026 17:31
> > > > Subject: Re: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero
> > > > fault
> > > >
> > > > 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?
> > >
> > > You are tight, Will update commit description.
> >
> > How can uart_get_baud_rate() return a zero value? If I am not mistaken even for the B0 case, it will
> > return 9600?
>
> As per the comment and code, this API can return 0.
>
> * If the new baud rate is invalid, try the @old termios setting. If it's still
> * invalid, we try 9600 baud. If that is also invalid 0 is returned.
>
> In drives/tty currently only 1 driver is checking the return value
> and it calls panic
>
> https://elixir.bootlin.com/linux/v7.0-rc7/source/drivers/tty/serial/apbuart.c#L214

Hmmm, more than 1:

icom.c:
if (!baud)
baud = 9600; /* B0 transition handled in rs_set_termios */

8250/8250_fintek.c:
if (!baud)
goto exit;

> I believe we should call panic, if baud =0, instead of proceeding.
> Geert, any thoughts??

There once was a warning, removed by:

commit 23bf72faaebdf2cb199c0ef8cf96467b10904b35
Author: Max Filippov <jcmvbkbc@xxxxxxxxx>
Date: Tue Oct 10 01:59:22 2023 -0700
serial: core: tidy invalid baudrate handling in uart_get_baud_rate
...
Clarify that 0 can be (and always could be) returned from the
uart_get_baud_rate. Don't issue a warning in that case.
...

--
Hugo Villeneuve