RE: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault
From: Biju Das
Date: Thu Apr 09 2026 - 03:41:55 EST
> -----Original Message-----
> From: Biju Das
> Sent: 08 April 2026 20:02
> To: Hugo Villeneuve <hugo@xxxxxxxxxxx>
> Cc: biju.das.au <biju.das.au@xxxxxxxxx>; Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>; Jiri Slaby
> <jirislaby@xxxxxxxxxx>; Geert Uytterhoeven <geert+renesas@xxxxxxxxx>; Thierry Bultel
> <thierry.bultel.yh@xxxxxxxxxxxxxx>; wsa+renesas <wsa+renesas@xxxxxxxxxxxxxxxxxxxx>; Prabhakar Mahadev
> Lad <prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx>; linux-kernel@xxxxxxxxxxxxxxx; linux-
> serial@xxxxxxxxxxxxxxx; linux-renesas-soc@xxxxxxxxxxxxxxx
> Subject: RE: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault
>
> Hi Hugo,
>
> > -----Original Message-----
> > From: Hugo Villeneuve <hugo@xxxxxxxxxxx>
> > Sent: 08 April 2026 19:15
> > Subject: Re: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault
> >
> > 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/
> > > ap
> > > buart.c#L214
> >
> > Hmmm, more than 1:
>
> >
> > icom.c:
> > if (!baud)
> > baud = 9600; /* B0 transition handled in rs_set_termios */
>
> A zero return from uart_get_baud_rate() is a normal, recoverable condition (unsupported rate requested
> by userspace) and must not crash the kernel.
>
> Or drop the check like other tty drivers, as SCIF/RSCI IP support 9600 baud rate.
May be setting a buadrate 115200 is safe in this cas like earlyprintk??
I will send next version setting buad = 115200, if uart_get_baud_rate() returns 0.
Cheers,
Biju