* [PATCH v2 0/2] serial: sh-sci/rsci: Fix divide by zero and clean up baud rate logic @ 2026-04-08 14:20 Biju 2026-04-08 14:20 ` [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault Biju 2026-04-08 14:20 ` [PATCH v2 2/2] serial: rsci: Remove goto and refactor baud rate clock selection Biju 0 siblings, 2 replies; 18+ messages in thread From: Biju @ 2026-04-08 14:20 UTC (permalink / raw) To: Greg Kroah-Hartman, Jiri Slaby Cc: Biju Das, Geert Uytterhoeven, Thierry Bultel, Wolfram Sang, Lad Prabhakar, linux-kernel, linux-serial, Biju Das, linux-renesas-soc From: Biju Das <biju.das.jz@bp.renesas.com> This series fixes a divide-by-zero in the sh-sci and rsci serial drivers and follows up with a cleanup of the baud rate clock selection logic in rsci that the fix exposed as unnecessarily complex. Patch 1 guards both uart_update_timeout() call sites in sci_set_termios() and rsci_set_termios() with a baud != 0 check. uart_update_timeout() divides by the baud rate internally, so passing zero causes a divide-by- zero fault when the hardware returns an unsupported or invalid rate. Patch 2 addresses a related issue reported by Pavel Machek: the goto-based early-exit pattern in rsci_set_termios() was obscuring the control flow. Since RSCI only ever uses a single clock source (SCI_FCK), the multi-clock candidate tracking variables (best_clk, min_err, brr1, srr1, cks1) were redundant. These are removed and the goto is replaced with a straight forward positive conditional block. ccr0_val and ccr4_val are also dropped in favour of hardcoded 0 at their writes. v1->v2: * Add a patch for avoiding divide-by-zero fault. * Dropped the check (abs(err) < abs(min_err) as it is always true. * Dropped variables best_clk and min_err as they are no longer needed. * Dropped intermediate variables brr1, cks1 and srr1; results are now written directly into brr, cks and srr. * Moved dev_dbg() inside the if (baud) block. * Dropped ccr0_val and ccr4_val, replaced with hardcoded 0 at their write sites, as they were never modified from their initial values. * Scoped variables err and srr locally within the if (baud) block. * Updated commit description. Biju Das (2): serial: sh-sci: Avoid divide by zero serial: rsci: Remove goto and refactor baud rate clock selection drivers/tty/serial/rsci.c | 36 +++++++++++++----------------------- drivers/tty/serial/sh-sci.c | 3 ++- 2 files changed, 15 insertions(+), 24 deletions(-) -- 2.43.0 ^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault 2026-04-08 14:20 [PATCH v2 0/2] serial: sh-sci/rsci: Fix divide by zero and clean up baud rate logic Biju @ 2026-04-08 14:20 ` Biju 2026-04-08 15:39 ` Geert Uytterhoeven 2026-04-08 16:30 ` Hugo Villeneuve 2026-04-08 14:20 ` [PATCH v2 2/2] serial: rsci: Remove goto and refactor baud rate clock selection Biju 1 sibling, 2 replies; 18+ messages in thread From: Biju @ 2026-04-08 14:20 UTC (permalink / raw) To: Greg Kroah-Hartman, Jiri Slaby Cc: Biju Das, Geert Uytterhoeven, Thierry Bultel, Wolfram Sang, Lad Prabhakar, linux-kernel, linux-serial, Biju Das, linux-renesas-soc From: Biju Das <biju.das.jz@bp.renesas.com> 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@bp.renesas.com> --- 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); /* byte size and parity */ bits = tty_get_frame_size(termios->c_cflag); -- 2.43.0 ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault 2026-04-08 14:20 ` [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault Biju @ 2026-04-08 15:39 ` Geert Uytterhoeven 2026-04-08 16:05 ` Biju Das 2026-04-08 16:30 ` Hugo Villeneuve 1 sibling, 1 reply; 18+ messages in thread From: Geert Uytterhoeven @ 2026-04-08 15:39 UTC (permalink / raw) To: Biju Cc: Greg Kroah-Hartman, Jiri Slaby, Biju Das, Thierry Bultel, Wolfram Sang, Lad Prabhakar, linux-kernel, linux-serial, linux-renesas-soc Hi Biju, On Wed, 8 Apr 2026 at 16:21, Biju <biju.das.au@gmail.com> wrote: > From: Biju Das <biju.das.jz@bp.renesas.com> > > 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@bp.renesas.com> 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: s->rx_frame = (10000 * bits) / (baud / 100); Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org 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 ^ permalink raw reply [flat|nested] 18+ messages in thread
* RE: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault 2026-04-08 15:39 ` Geert Uytterhoeven @ 2026-04-08 16:05 ` Biju Das 0 siblings, 0 replies; 18+ messages in thread From: Biju Das @ 2026-04-08 16:05 UTC (permalink / raw) To: geert, biju.das.au Cc: Greg Kroah-Hartman, Jiri Slaby, Thierry Bultel, wsa+renesas, Prabhakar Mahadev Lad, linux-kernel, linux-serial, linux-renesas-soc Hi Geert, Thanks for the feedback. > -----Original Message----- > From: Geert Uytterhoeven <geert@linux-m68k.org> > 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@gmail.com> wrote: > > From: Biju Das <biju.das.jz@bp.renesas.com> > > > > 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@bp.renesas.com> > > 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@linux-m68k.org > > 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 ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault 2026-04-08 14:20 ` [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault Biju 2026-04-08 15:39 ` Geert Uytterhoeven @ 2026-04-08 16:30 ` Hugo Villeneuve 2026-04-08 16:35 ` Biju Das 1 sibling, 1 reply; 18+ messages in thread From: Hugo Villeneuve @ 2026-04-08 16:30 UTC (permalink / raw) To: Biju Cc: Greg Kroah-Hartman, Jiri Slaby, Biju Das, Geert Uytterhoeven, Thierry Bultel, Wolfram Sang, Lad Prabhakar, linux-kernel, linux-serial, linux-renesas-soc Hi Biju, On Wed, 8 Apr 2026 15:20:58 +0100 Biju <biju.das.au@gmail.com> wrote: > From: Biju Das <biju.das.jz@bp.renesas.com> > > 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@bp.renesas.com> 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 ^ permalink raw reply [flat|nested] 18+ messages in thread
* RE: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault 2026-04-08 16:30 ` Hugo Villeneuve @ 2026-04-08 16:35 ` Biju Das 2026-04-08 16:51 ` Hugo Villeneuve 0 siblings, 1 reply; 18+ messages in thread From: Biju Das @ 2026-04-08 16:35 UTC (permalink / raw) To: Hugo Villeneuve, biju.das.au Cc: Greg Kroah-Hartman, Jiri Slaby, Geert Uytterhoeven, Thierry Bultel, wsa+renesas, Prabhakar Mahadev Lad, linux-kernel, linux-serial, linux-renesas-soc Hi Hugo, Thanks for the feedback. > -----Original Message----- > From: Hugo Villeneuve <hugo@hugovil.com> > 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@gmail.com> wrote: > > > From: Biju Das <biju.das.jz@bp.renesas.com> > > > > 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. > > > > > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> > > Missing Fixes tag? I will split patch into 2 adding 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: + /* Avoid divide-by-zero fault in divider operations */ + if (!baud) + baud = 100; + Plan is to update the code with the above change, that will cover All divide-by-zero case in this function. Cheers, Biju ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault 2026-04-08 16:35 ` Biju Das @ 2026-04-08 16:51 ` Hugo Villeneuve 2026-04-08 17:25 ` Biju Das 0 siblings, 1 reply; 18+ messages in thread From: Hugo Villeneuve @ 2026-04-08 16:51 UTC (permalink / raw) To: Biju Das Cc: biju.das.au, Greg Kroah-Hartman, Jiri Slaby, Geert Uytterhoeven, Thierry Bultel, wsa+renesas, Prabhakar Mahadev Lad, linux-kernel, linux-serial, linux-renesas-soc Hi Biju, On Wed, 8 Apr 2026 16:35:44 +0000 Biju Das <biju.das.jz@bp.renesas.com> wrote: > Hi Hugo, > > Thanks for the feedback. > > > -----Original Message----- > > From: Hugo Villeneuve <hugo@hugovil.com> > > 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@gmail.com> wrote: > > > > > From: Biju Das <biju.das.jz@bp.renesas.com> > > > > > > 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? What are other consequences if a zero value is returned apart from the division by zero fault? Is it ok (or logical) then to proceed with the rest of the configuration? > > > > > > > > > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> > > > > Missing Fixes tag? > > I will split patch into 2 adding 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: > > + /* Avoid divide-by-zero fault in divider operations */ > + if (!baud) > + baud = 100; > + > > Plan is to update the code with the above change, that will cover > All divide-by-zero case in this function. As stated above, does it makes sense to proceed if baud was zero? > > Cheers, > Biju -- Hugo Villeneuve ^ permalink raw reply [flat|nested] 18+ messages in thread
* RE: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault 2026-04-08 16:51 ` Hugo Villeneuve @ 2026-04-08 17:25 ` Biju Das 2026-04-08 18:15 ` Hugo Villeneuve 2026-04-13 10:24 ` Geert Uytterhoeven 0 siblings, 2 replies; 18+ messages in thread From: Biju Das @ 2026-04-08 17:25 UTC (permalink / raw) To: Hugo Villeneuve Cc: biju.das.au, Greg Kroah-Hartman, Jiri Slaby, Geert Uytterhoeven, Thierry Bultel, wsa+renesas, Prabhakar Mahadev Lad, linux-kernel, linux-serial, linux-renesas-soc Hi Hugo, > -----Original Message----- > From: Hugo Villeneuve <hugo@hugovil.com> > 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@bp.renesas.com> wrote: > > > Hi Hugo, > > > > Thanks for the feedback. > > > > > -----Original Message----- > > > From: Hugo Villeneuve <hugo@hugovil.com> > > > 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@gmail.com> wrote: > > > > > > > From: Biju Das <biju.das.jz@bp.renesas.com> > > > > > > > > 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 I believe we should call panic, if baud =0, instead of proceeding. Geert, any thoughts?? Cheers, Biju ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault 2026-04-08 17:25 ` Biju Das @ 2026-04-08 18:15 ` Hugo Villeneuve 2026-04-08 19:02 ` Biju Das 2026-04-13 10:24 ` Geert Uytterhoeven 1 sibling, 1 reply; 18+ messages in thread From: Hugo Villeneuve @ 2026-04-08 18:15 UTC (permalink / raw) To: Biju Das Cc: biju.das.au, Greg Kroah-Hartman, Jiri Slaby, Geert Uytterhoeven, Thierry Bultel, wsa+renesas, Prabhakar Mahadev Lad, linux-kernel, linux-serial, linux-renesas-soc Hi Biju, On Wed, 8 Apr 2026 17:25:19 +0000 Biju Das <biju.das.jz@bp.renesas.com> wrote: > Hi Hugo, > > > -----Original Message----- > > From: Hugo Villeneuve <hugo@hugovil.com> > > 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@bp.renesas.com> wrote: > > > > > Hi Hugo, > > > > > > Thanks for the feedback. > > > > > > > -----Original Message----- > > > > From: Hugo Villeneuve <hugo@hugovil.com> > > > > 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@gmail.com> wrote: > > > > > > > > > From: Biju Das <biju.das.jz@bp.renesas.com> > > > > > > > > > > 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@gmail.com> 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 ^ permalink raw reply [flat|nested] 18+ messages in thread
* RE: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault 2026-04-08 18:15 ` Hugo Villeneuve @ 2026-04-08 19:02 ` Biju Das 2026-04-09 7:40 ` Biju Das 0 siblings, 1 reply; 18+ messages in thread From: Biju Das @ 2026-04-08 19:02 UTC (permalink / raw) To: Hugo Villeneuve Cc: biju.das.au, Greg Kroah-Hartman, Jiri Slaby, Geert Uytterhoeven, Thierry Bultel, wsa+renesas, Prabhakar Mahadev Lad, linux-kernel, linux-serial, linux-renesas-soc Hi Hugo, > -----Original Message----- > From: Hugo Villeneuve <hugo@hugovil.com> > 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@bp.renesas.com> wrote: > > > Hi Hugo, > > > > > -----Original Message----- > > > From: Hugo Villeneuve <hugo@hugovil.com> > > > 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@bp.renesas.com> wrote: > > > > > > > Hi Hugo, > > > > > > > > Thanks for the feedback. > > > > > > > > > -----Original Message----- > > > > > From: Hugo Villeneuve <hugo@hugovil.com> > > > > > 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@gmail.com> > > > > > wrote: > > > > > > > > > > > From: Biju Das <biju.das.jz@bp.renesas.com> > > > > > > > > > > > > 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. Cheers, Biju ^ permalink raw reply [flat|nested] 18+ messages in thread
* RE: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault 2026-04-08 19:02 ` Biju Das @ 2026-04-09 7:40 ` Biju Das 2026-04-09 14:16 ` Hugo Villeneuve 0 siblings, 1 reply; 18+ messages in thread From: Biju Das @ 2026-04-09 7:40 UTC (permalink / raw) To: Hugo Villeneuve Cc: biju.das.au, Greg Kroah-Hartman, Jiri Slaby, Geert Uytterhoeven, Thierry Bultel, wsa+renesas, Prabhakar Mahadev Lad, linux-kernel, linux-serial, linux-renesas-soc > -----Original Message----- > From: Biju Das > Sent: 08 April 2026 20:02 > To: Hugo Villeneuve <hugo@hugovil.com> > Cc: biju.das.au <biju.das.au@gmail.com>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Jiri Slaby > <jirislaby@kernel.org>; Geert Uytterhoeven <geert+renesas@glider.be>; Thierry Bultel > <thierry.bultel.yh@bp.renesas.com>; wsa+renesas <wsa+renesas@sang-engineering.com>; Prabhakar Mahadev > Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>; linux-kernel@vger.kernel.org; linux- > serial@vger.kernel.org; linux-renesas-soc@vger.kernel.org > Subject: RE: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault > > Hi Hugo, > > > -----Original Message----- > > From: Hugo Villeneuve <hugo@hugovil.com> > > 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@bp.renesas.com> wrote: > > > > > Hi Hugo, > > > > > > > -----Original Message----- > > > > From: Hugo Villeneuve <hugo@hugovil.com> > > > > 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@bp.renesas.com> wrote: > > > > > > > > > Hi Hugo, > > > > > > > > > > Thanks for the feedback. > > > > > > > > > > > -----Original Message----- > > > > > > From: Hugo Villeneuve <hugo@hugovil.com> > > > > > > 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@gmail.com> > > > > > > wrote: > > > > > > > > > > > > > From: Biju Das <biju.das.jz@bp.renesas.com> > > > > > > > > > > > > > > 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 ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault 2026-04-09 7:40 ` Biju Das @ 2026-04-09 14:16 ` Hugo Villeneuve 0 siblings, 0 replies; 18+ messages in thread From: Hugo Villeneuve @ 2026-04-09 14:16 UTC (permalink / raw) To: Biju Das Cc: biju.das.au, Greg Kroah-Hartman, Jiri Slaby, Geert Uytterhoeven, Thierry Bultel, wsa+renesas, Prabhakar Mahadev Lad, linux-kernel, linux-serial, linux-renesas-soc Hi Biju, On Thu, 9 Apr 2026 07:40:02 +0000 Biju Das <biju.das.jz@bp.renesas.com> wrote: > > > > -----Original Message----- > > From: Biju Das > > Sent: 08 April 2026 20:02 > > To: Hugo Villeneuve <hugo@hugovil.com> > > Cc: biju.das.au <biju.das.au@gmail.com>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Jiri Slaby > > <jirislaby@kernel.org>; Geert Uytterhoeven <geert+renesas@glider.be>; Thierry Bultel > > <thierry.bultel.yh@bp.renesas.com>; wsa+renesas <wsa+renesas@sang-engineering.com>; Prabhakar Mahadev > > Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>; linux-kernel@vger.kernel.org; linux- > > serial@vger.kernel.org; linux-renesas-soc@vger.kernel.org > > Subject: RE: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault > > > > Hi Hugo, > > > > > -----Original Message----- > > > From: Hugo Villeneuve <hugo@hugovil.com> > > > 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@bp.renesas.com> wrote: > > > > > > > Hi Hugo, > > > > > > > > > -----Original Message----- > > > > > From: Hugo Villeneuve <hugo@hugovil.com> > > > > > 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@bp.renesas.com> wrote: > > > > > > > > > > > Hi Hugo, > > > > > > > > > > > > Thanks for the feedback. > > > > > > > > > > > > > -----Original Message----- > > > > > > > From: Hugo Villeneuve <hugo@hugovil.com> > > > > > > > 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@gmail.com> > > > > > > > wrote: > > > > > > > > > > > > > > > From: Biju Das <biju.das.jz@bp.renesas.com> > > > > > > > > > > > > > > > > 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. Is it logical to proceed with configuration if it returned zero? Also we still pass 0 as a minimum value in uart_get_baud_rate(), so that a baud rate of 75, for example, would be valid, but would trigger a fault later (division by zero). Wouldn't it be a good idea to also set a proper minimum baud rate? -- Hugo Villeneuve ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault 2026-04-08 17:25 ` Biju Das 2026-04-08 18:15 ` Hugo Villeneuve @ 2026-04-13 10:24 ` Geert Uytterhoeven 2026-04-16 16:31 ` Biju Das 1 sibling, 1 reply; 18+ messages in thread From: Geert Uytterhoeven @ 2026-04-13 10:24 UTC (permalink / raw) To: Biju Das Cc: Hugo Villeneuve, biju.das.au, Greg Kroah-Hartman, Jiri Slaby, Thierry Bultel, wsa+renesas, Prabhakar Mahadev Lad, linux-kernel, linux-serial, linux-renesas-soc Hi Biju, On Wed, 8 Apr 2026 at 19:25, Biju Das <biju.das.jz@bp.renesas.com> wrote: > > From: Hugo Villeneuve <hugo@hugovil.com> > > On Wed, 8 Apr 2026 16:35:44 +0000 > > Biju Das <biju.das.jz@bp.renesas.com> wrote: > > > > From: Hugo Villeneuve <hugo@hugovil.com> > > > > Biju <biju.das.au@gmail.com> wrote: > > > > > From: Biju Das <biju.das.jz@bp.renesas.com> > > > > > > > > > > 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 > > > I believe we should call panic, if baud =0, instead of proceeding. > > Geert, any thoughts?? IIRC, baud == 0 can (only?) happen when using earlyprintk on a non-DT system, where the serial console should just keep on using the settings programmed by the firmware. So any config register writes should be skipped. On DT systems, even earlycon uses the bitrate from chosen/stdout-path. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org 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 ^ permalink raw reply [flat|nested] 18+ messages in thread
* RE: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault 2026-04-13 10:24 ` Geert Uytterhoeven @ 2026-04-16 16:31 ` Biju Das 0 siblings, 0 replies; 18+ messages in thread From: Biju Das @ 2026-04-16 16:31 UTC (permalink / raw) To: geert Cc: Hugo Villeneuve, biju.das.au, Greg Kroah-Hartman, Jiri Slaby, Thierry Bultel, wsa+renesas, Prabhakar Mahadev Lad, linux-kernel, linux-serial, linux-renesas-soc Hi Geert, Thanks for the feedback. > -----Original Message----- > From: Geert Uytterhoeven <geert@linux-m68k.org> > Sent: 13 April 2026 11:25 > Subject: Re: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault > > Hi Biju, > > On Wed, 8 Apr 2026 at 19:25, Biju Das <biju.das.jz@bp.renesas.com> wrote: > > > From: Hugo Villeneuve <hugo@hugovil.com> On Wed, 8 Apr 2026 16:35:44 > > > +0000 Biju Das <biju.das.jz@bp.renesas.com> wrote: > > > > > From: Hugo Villeneuve <hugo@hugovil.com> Biju > > > > > <biju.das.au@gmail.com> wrote: > > > > > > From: Biju Das <biju.das.jz@bp.renesas.com> > > > > > > > > > > > > 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 > > > > > > I believe we should call panic, if baud =0, instead of proceeding. > > > > Geert, any thoughts?? > > IIRC, baud == 0 can (only?) happen when using earlyprintk on a non-DT system, where the serial console > should just keep on using the settings programmed by the firmware. So any config register writes > should be skipped. > > On DT systems, even earlycon uses the bitrate from chosen/stdout-path. In that case, I will drop the zero baud check. I will add a new patch with below change which is algebraically equivalent but eliminates the intermediate division, making a zero divisor impossible for any valid baud rate. - s->rx_frame = (10000 * bits) / (baud / 100); + s->rx_frame = (10000 * bits) * 100 / baud; Cheers, Biju ^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2 2/2] serial: rsci: Remove goto and refactor baud rate clock selection 2026-04-08 14:20 [PATCH v2 0/2] serial: sh-sci/rsci: Fix divide by zero and clean up baud rate logic Biju 2026-04-08 14:20 ` [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault Biju @ 2026-04-08 14:20 ` Biju 2026-04-08 15:45 ` Geert Uytterhoeven 1 sibling, 1 reply; 18+ messages in thread From: Biju @ 2026-04-08 14:20 UTC (permalink / raw) To: Greg Kroah-Hartman, Jiri Slaby Cc: Biju Das, Geert Uytterhoeven, Thierry Bultel, Wolfram Sang, Lad Prabhakar, linux-kernel, linux-serial, Biju Das, linux-renesas-soc, Pavel Machek From: Biju Das <biju.das.jz@bp.renesas.com> Replace the goto done pattern in rsci_set_termios() with a positive conditional block. When baud rate is zero, the clock selection logic is now simply skipped rather than jumping to a 'done' label, eliminating the goto entirely. Since RSCI only uses a single clock source (SCI_FCK), the multi-clock tracking variables (best_clk, min_err, brr1, srr1, cks1) are redundant and removed. ccr0_val and ccr4_val are likewise dropped, replaced with hardcoded 0 at their write sites, as they were never modified from their initial zero values. No functional change intended. Reported-by: Pavel Machek <pavel@nabladev.com> Closes: https://lore.kernel.org/all/abPpZULsXhRmXTX9@duo.ucw.cz/ Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> --- v1->v2: * Dropped the check (abs(err) < abs(min_err) as it is always true. * Dropped the check (abs(err) < abs(min_err) as it is always true. * Dropped variables best_clk and min_err as they are no longer needed. * Dropped intermediate variables brr1, cks1 and srr1; results are now written directly into brr, cks and srr. * Moved dev_dbg() inside the if (baud) block. * Dropped ccr0_val and ccr4_val, replaced with hardcoded 0 at their write sites, as they were never modified from their initial values. * Scoped variables err and srr locally within the if (baud) block. * Updated commit description. --- drivers/tty/serial/rsci.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/drivers/tty/serial/rsci.c b/drivers/tty/serial/rsci.c index a0858bab0822..c2440fd5c02d 100644 --- a/drivers/tty/serial/rsci.c +++ b/drivers/tty/serial/rsci.c @@ -217,16 +217,13 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios, const struct ktermios *old) { unsigned int ccr2_val = CCR2_INIT, ccr3_val = CCR3_INIT; - unsigned int ccr0_val = 0, ccr1_val = 0, ccr4_val = 0; - unsigned int brr1 = 255, cks1 = 0, srr1 = 15; struct sci_port *s = to_sci_port(port); unsigned int brr = 255, cks = 0; - int min_err = INT_MAX, err; - unsigned long max_freq = 0; + unsigned int ccr1_val = 0; + unsigned long max_freq; unsigned int baud, i; unsigned long flags; unsigned int ctrl; - int best_clk = -1; if ((termios->c_cflag & CSIZE) == CS7) { ccr3_val |= CCR3_CHR0; @@ -265,23 +262,15 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios, } baud = uart_get_baud_rate(port, termios, old, 0, max_freq); - if (!baud) - goto done; - - /* Divided Functional Clock using standard Bit Rate Register */ - err = sci_scbrr_calc(s, baud, &brr1, &srr1, &cks1); - if (abs(err) < abs(min_err)) { - best_clk = SCI_FCK; - ccr0_val = 0; - min_err = err; - brr = brr1; - cks = cks1; - } + if (baud) { + unsigned int srr; + int err; -done: - if (best_clk >= 0) + /* Divided Functional Clock using standard Bit Rate Register */ + err = sci_scbrr_calc(s, baud, &brr, &srr, &cks); dev_dbg(port->dev, "Using clk %pC for %u%+d bps\n", - s->clks[best_clk], baud, min_err); + s->clks[SCI_FCK], baud, err); + } sci_port_enable(s); uart_port_lock_irqsave(port, &flags); @@ -289,7 +278,7 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios, if (baud) uart_update_timeout(port, termios->c_cflag, baud); - rsci_serial_out(port, CCR0, ccr0_val); + rsci_serial_out(port, CCR0, 0); ccr3_val |= CCR3_FM; rsci_serial_out(port, CCR3, ccr3_val); @@ -298,7 +287,7 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios, rsci_serial_out(port, CCR2, ccr2_val); rsci_serial_out(port, CCR1, ccr1_val); - rsci_serial_out(port, CCR4, ccr4_val); + rsci_serial_out(port, CCR4, 0); ctrl = rsci_serial_in(port, FCR); ctrl |= (FCR_RFRST | FCR_TFRST); -- 2.43.0 ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 2/2] serial: rsci: Remove goto and refactor baud rate clock selection 2026-04-08 14:20 ` [PATCH v2 2/2] serial: rsci: Remove goto and refactor baud rate clock selection Biju @ 2026-04-08 15:45 ` Geert Uytterhoeven 2026-04-08 15:53 ` Geert Uytterhoeven 0 siblings, 1 reply; 18+ messages in thread From: Geert Uytterhoeven @ 2026-04-08 15:45 UTC (permalink / raw) To: Biju Cc: Greg Kroah-Hartman, Jiri Slaby, Biju Das, Thierry Bultel, Wolfram Sang, Lad Prabhakar, linux-kernel, linux-serial, linux-renesas-soc, Pavel Machek On Wed, 8 Apr 2026 at 16:21, Biju <biju.das.au@gmail.com> wrote: > From: Biju Das <biju.das.jz@bp.renesas.com> > > Replace the goto done pattern in rsci_set_termios() with a positive > conditional block. When baud rate is zero, the clock selection logic > is now simply skipped rather than jumping to a 'done' label, eliminating > the goto entirely. > > Since RSCI only uses a single clock source (SCI_FCK), the multi-clock > tracking variables (best_clk, min_err, brr1, srr1, cks1) are redundant > and removed. ccr0_val and ccr4_val are likewise dropped, replaced with > hardcoded 0 at their write sites, as they were never modified from their > initial zero values. > > No functional change intended. > > Reported-by: Pavel Machek <pavel@nabladev.com> > Closes: https://lore.kernel.org/all/abPpZULsXhRmXTX9@duo.ucw.cz/ > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> > --- > v1->v2: > * Dropped the check (abs(err) < abs(min_err) as it is always true. > * Dropped the check (abs(err) < abs(min_err) as it is always true. > * Dropped variables best_clk and min_err as they are no longer needed. > * Dropped intermediate variables brr1, cks1 and srr1; results are now > written directly into brr, cks and srr. > * Moved dev_dbg() inside the if (baud) block. > * Dropped ccr0_val and ccr4_val, replaced with hardcoded 0 at their > write sites, as they were never modified from their initial values. > * Scoped variables err and srr locally within the if (baud) block. > * Updated commit description. Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org 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 ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 2/2] serial: rsci: Remove goto and refactor baud rate clock selection 2026-04-08 15:45 ` Geert Uytterhoeven @ 2026-04-08 15:53 ` Geert Uytterhoeven 2026-04-08 16:01 ` Biju Das 0 siblings, 1 reply; 18+ messages in thread From: Geert Uytterhoeven @ 2026-04-08 15:53 UTC (permalink / raw) To: Biju Cc: Greg Kroah-Hartman, Jiri Slaby, Biju Das, Thierry Bultel, Wolfram Sang, Lad Prabhakar, linux-kernel, linux-serial, linux-renesas-soc, Pavel Machek Hi Biju, On Wed, 8 Apr 2026 at 17:45, Geert Uytterhoeven <geert@linux-m68k.org> wrote: > On Wed, 8 Apr 2026 at 16:21, Biju <biju.das.au@gmail.com> wrote: > > From: Biju Das <biju.das.jz@bp.renesas.com> > > > > Replace the goto done pattern in rsci_set_termios() with a positive > > conditional block. When baud rate is zero, the clock selection logic > > is now simply skipped rather than jumping to a 'done' label, eliminating > > the goto entirely. > > > > Since RSCI only uses a single clock source (SCI_FCK), the multi-clock > > tracking variables (best_clk, min_err, brr1, srr1, cks1) are redundant > > and removed. ccr0_val and ccr4_val are likewise dropped, replaced with > > hardcoded 0 at their write sites, as they were never modified from their > > initial zero values. > > > > No functional change intended. > > > > Reported-by: Pavel Machek <pavel@nabladev.com> > > Closes: https://lore.kernel.org/all/abPpZULsXhRmXTX9@duo.ucw.cz/ > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> > > --- > > v1->v2: > > * Dropped the check (abs(err) < abs(min_err) as it is always true. > > * Dropped the check (abs(err) < abs(min_err) as it is always true. > > * Dropped variables best_clk and min_err as they are no longer needed. > > * Dropped intermediate variables brr1, cks1 and srr1; results are now > > written directly into brr, cks and srr. > > * Moved dev_dbg() inside the if (baud) block. > > * Dropped ccr0_val and ccr4_val, replaced with hardcoded 0 at their > > write sites, as they were never modified from their initial values. > > * Scoped variables err and srr locally within the if (baud) block. > > * Updated commit description. > > Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> I spoke too soon, you need one more change to make it build: --- a/drivers/tty/serial/rsci.c +++ b/drivers/tty/serial/rsci.c @@ -308,8 +308,7 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios, rsci_serial_out(port, CFCLR, CFCLR_CLRFLAG); rsci_serial_out(port, FFCLR, FFCLR_DRC); - ccr0_val |= CCR0_RE; - rsci_serial_out(port, CCR0, ccr0_val); + rsci_serial_out(port, CCR0, CCR0_RE); if ((termios->c_cflag & CREAD) != 0) rsci_start_rx(port); Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org 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 ^ permalink raw reply [flat|nested] 18+ messages in thread
* RE: [PATCH v2 2/2] serial: rsci: Remove goto and refactor baud rate clock selection 2026-04-08 15:53 ` Geert Uytterhoeven @ 2026-04-08 16:01 ` Biju Das 0 siblings, 0 replies; 18+ messages in thread From: Biju Das @ 2026-04-08 16:01 UTC (permalink / raw) To: geert, biju.das.au Cc: Greg Kroah-Hartman, Jiri Slaby, Thierry Bultel, wsa+renesas, Prabhakar Mahadev Lad, linux-kernel, linux-serial, linux-renesas-soc, Pavel Machek Hi Geert, > -----Original Message----- > From: Geert Uytterhoeven <geert@linux-m68k.org> > Sent: 08 April 2026 16:53 > Subject: Re: [PATCH v2 2/2] serial: rsci: Remove goto and refactor baud rate clock selection > > Hi Biju, > > On Wed, 8 Apr 2026 at 17:45, Geert Uytterhoeven <geert@linux-m68k.org> wrote: > > On Wed, 8 Apr 2026 at 16:21, Biju <biju.das.au@gmail.com> wrote: > > > From: Biju Das <biju.das.jz@bp.renesas.com> > > > > > > Replace the goto done pattern in rsci_set_termios() with a positive > > > conditional block. When baud rate is zero, the clock selection logic > > > is now simply skipped rather than jumping to a 'done' label, > > > eliminating the goto entirely. > > > > > > Since RSCI only uses a single clock source (SCI_FCK), the > > > multi-clock tracking variables (best_clk, min_err, brr1, srr1, cks1) > > > are redundant and removed. ccr0_val and ccr4_val are likewise > > > dropped, replaced with hardcoded 0 at their write sites, as they > > > were never modified from their initial zero values. > > > > > > No functional change intended. > > > > > > Reported-by: Pavel Machek <pavel@nabladev.com> > > > Closes: https://lore.kernel.org/all/abPpZULsXhRmXTX9@duo.ucw.cz/ > > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> > > > --- > > > v1->v2: > > > * Dropped the check (abs(err) < abs(min_err) as it is always true. > > > * Dropped the check (abs(err) < abs(min_err) as it is always true. > > > * Dropped variables best_clk and min_err as they are no longer needed. > > > * Dropped intermediate variables brr1, cks1 and srr1; results are now > > > written directly into brr, cks and srr. > > > * Moved dev_dbg() inside the if (baud) block. > > > * Dropped ccr0_val and ccr4_val, replaced with hardcoded 0 at their > > > write sites, as they were never modified from their initial values. > > > * Scoped variables err and srr locally within the if (baud) block. > > > * Updated commit description. > > > > Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> > > I spoke too soon, you need one more change to make it build: > > --- a/drivers/tty/serial/rsci.c > +++ b/drivers/tty/serial/rsci.c > @@ -308,8 +308,7 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios, > rsci_serial_out(port, CFCLR, CFCLR_CLRFLAG); > rsci_serial_out(port, FFCLR, FFCLR_DRC); > > - ccr0_val |= CCR0_RE; > - rsci_serial_out(port, CCR0, ccr0_val); > + rsci_serial_out(port, CCR0, CCR0_RE); Oops, I missed this. Cheers, Biju ^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2026-04-16 16:31 UTC | newest] Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-04-08 14:20 [PATCH v2 0/2] serial: sh-sci/rsci: Fix divide by zero and clean up baud rate logic Biju 2026-04-08 14:20 ` [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault Biju 2026-04-08 15:39 ` Geert Uytterhoeven 2026-04-08 16:05 ` Biju Das 2026-04-08 16:30 ` Hugo Villeneuve 2026-04-08 16:35 ` Biju Das 2026-04-08 16:51 ` Hugo Villeneuve 2026-04-08 17:25 ` Biju Das 2026-04-08 18:15 ` Hugo Villeneuve 2026-04-08 19:02 ` Biju Das 2026-04-09 7:40 ` Biju Das 2026-04-09 14:16 ` Hugo Villeneuve 2026-04-13 10:24 ` Geert Uytterhoeven 2026-04-16 16:31 ` Biju Das 2026-04-08 14:20 ` [PATCH v2 2/2] serial: rsci: Remove goto and refactor baud rate clock selection Biju 2026-04-08 15:45 ` Geert Uytterhoeven 2026-04-08 15:53 ` Geert Uytterhoeven 2026-04-08 16:01 ` Biju Das
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®