Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH v3 0/3] serial: sh-sci/rsci: Fix divide-by-zero and clean up baud rate handling
@ 2026-04-20 14:04 Biju
  2026-04-20 14:04 ` [PATCH v3 1/3] serial: sh-sci: Avoid divide-by-zero fault Biju
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Biju @ 2026-04-20 14:04 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: Biju Das, Geert Uytterhoeven, Lad Prabhakar, Thierry Bultel,
	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 fault in the SH-SCI driver and cleans
up dead code and redundant variables related to baud rate handling in both
the SH-SCI and RSCI drivers.

Patch 1 fixes a divide-by-zero fault in sci_set_termios() where the
expression (10000 * bits) / (baud / 100) could divide by zero if baud is
less than 100. The expression is rewritten as (10000 * bits) * 100 / baud,
which is algebraically equivalent but eliminates the intermediate
division.

Patch 2 removes the dead zero baud rate guard from both sci_set_termios()
and rsci_set_termios(). On DT systems, uart_get_baud_rate() never returns
zero, making the if (!baud) goto done; check and its associated done label
unreachable dead code.

Patch 3 refactors the baud rate clock selection in rsci_set_termios().
Since RSCI only supports a single clock source (SCI_FCK), the multi-clock
tracking variables are redundant and removed. ccr0_val and ccr4_val, which
were never modified from their initial zero values, are replaced with
hardcoded 0 at their write sites.

v2->v3:
 * Added a patch to rewrite rx_frame calculation to avoid divide-by-zero.
 * Added a patch to drop zero baud check from sh-sci and rsci drivers.
 * Dropped reported by tag as the goto statement in rsci_set_termios()
   removed in the previous patch.
 * baud check removed by previous patch.
 * Added missing macro CCR0_RE while dropping ccr0_val variable.
 * Updated commit description for patch#3.
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 (3):
  serial: sh-sci: Avoid divide-by-zero fault
  serial: sh-sci: Drop check for zero baud rate from
    uart_get_baud_rate()
  serial: rsci: Refactor baud rate clock selection

 drivers/tty/serial/rsci.c   | 34 ++++++++++------------------------
 drivers/tty/serial/sh-sci.c |  4 +---
 2 files changed, 11 insertions(+), 27 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v3 1/3] serial: sh-sci: Avoid divide-by-zero fault
  2026-04-20 14:04 [PATCH v3 0/3] serial: sh-sci/rsci: Fix divide-by-zero and clean up baud rate handling Biju
@ 2026-04-20 14:04 ` Biju
  2026-04-20 14:04 ` [PATCH v3 2/3] serial: sh-sci: Drop check for zero baud rate from uart_get_baud_rate() Biju
  2026-04-20 14:04 ` [PATCH v3 3/3] serial: rsci: Refactor baud rate clock selection Biju
  2 siblings, 0 replies; 10+ messages in thread
From: Biju @ 2026-04-20 14:04 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: Biju Das, Geert Uytterhoeven, Lad Prabhakar, Thierry Bultel,
	linux-kernel, linux-serial, Biju Das, linux-renesas-soc

From: Biju Das <biju.das.jz@bp.renesas.com>

The expression (10000 * bits) / (baud / 100) can produce a divide-by-zero
if baud is less than 100, since integer division yields zero before the
outer divide occurs. Rewrite it as (10000 * bits) * 100 / baud, which is
algebraically equivalent but eliminates the intermediate division, making
a zero divisor impossible for any valid baud rate.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v3:
 * New patch.
---
 drivers/tty/serial/sh-sci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 6c819b6b2425..7473b26ce9cf 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2915,7 +2915,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	}
 
 	/* Calculate delay for 2 DMA buffers (4 FIFO). */
-	s->rx_frame = (10000 * bits) / (baud / 100);
+	s->rx_frame = (10000 * bits) * 100 / baud;
 #ifdef CONFIG_SERIAL_SH_SCI_DMA
 	s->rx_timeout = s->buf_len_rx * 2 * s->rx_frame;
 #endif
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v3 2/3] serial: sh-sci: Drop check for zero baud rate from uart_get_baud_rate()
  2026-04-20 14:04 [PATCH v3 0/3] serial: sh-sci/rsci: Fix divide-by-zero and clean up baud rate handling Biju
  2026-04-20 14:04 ` [PATCH v3 1/3] serial: sh-sci: Avoid divide-by-zero fault Biju
@ 2026-04-20 14:04 ` Biju
  2026-04-20 15:59   ` Hugo Villeneuve
  2026-04-22  7:04   ` Geert Uytterhoeven
  2026-04-20 14:04 ` [PATCH v3 3/3] serial: rsci: Refactor baud rate clock selection Biju
  2 siblings, 2 replies; 10+ messages in thread
From: Biju @ 2026-04-20 14:04 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: Biju Das, Geert Uytterhoeven, Lad Prabhakar, Thierry Bultel,
	linux-kernel, linux-serial, Biju Das, linux-renesas-soc

From: Biju Das <biju.das.jz@bp.renesas.com>

On DT systems, a zero baud rate from uart_get_baud_rate() is not possible
even earlycon derives its bit rate from chosen/stdout-path. The zero baud
guard and its associated done label are therefore dead code. So remove it.

Also drop the unused done label from rsci_set_termios().

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v3:
 * New patch
---
 drivers/tty/serial/rsci.c   | 3 ---
 drivers/tty/serial/sh-sci.c | 2 --
 2 files changed, 5 deletions(-)

diff --git a/drivers/tty/serial/rsci.c b/drivers/tty/serial/rsci.c
index b00c9e385169..40db9daa4272 100644
--- a/drivers/tty/serial/rsci.c
+++ b/drivers/tty/serial/rsci.c
@@ -265,8 +265,6 @@ 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);
@@ -278,7 +276,6 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios,
 		cks = cks1;
 	}
 
-done:
 	if (best_clk >= 0)
 		dev_dbg(port->dev, "Using clk %pC for %u%+d bps\n",
 			s->clks[best_clk], baud, min_err);
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 7473b26ce9cf..9be359e04995 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2719,8 +2719,6 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 		max_freq = max(max_freq, s->clk_rates[i]);
 
 	baud = uart_get_baud_rate(port, termios, old, 0, max_freq / min_sr(s));
-	if (!baud)
-		goto done;
 
 	/*
 	 * There can be multiple sources for the sampling clock.  Find the one
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v3 3/3] serial: rsci: Refactor baud rate clock selection
  2026-04-20 14:04 [PATCH v3 0/3] serial: sh-sci/rsci: Fix divide-by-zero and clean up baud rate handling Biju
  2026-04-20 14:04 ` [PATCH v3 1/3] serial: sh-sci: Avoid divide-by-zero fault Biju
  2026-04-20 14:04 ` [PATCH v3 2/3] serial: sh-sci: Drop check for zero baud rate from uart_get_baud_rate() Biju
@ 2026-04-20 14:04 ` Biju
  2026-04-22  6:26   ` Biju Das
  2 siblings, 1 reply; 10+ messages in thread
From: Biju @ 2026-04-20 14:04 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: Biju Das, Geert Uytterhoeven, Lad Prabhakar, Thierry Bultel,
	linux-kernel, linux-serial, Biju Das, linux-renesas-soc

From: Biju Das <biju.das.jz@bp.renesas.com>

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.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v2->v3:
 * Dropped reported by tag as the goto statement in rsci_set_termios()
   removed in the previous patch.
 * baud check removed by previous patch.
 * Added missing macro CCR0_RE while dropping ccr0_val variable.
 * Updated commit description.
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 | 31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/drivers/tty/serial/rsci.c b/drivers/tty/serial/rsci.c
index 40db9daa4272..444e89696310 100644
--- a/drivers/tty/serial/rsci.c
+++ b/drivers/tty/serial/rsci.c
@@ -217,16 +217,15 @@ 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;
+	unsigned int srr;
+	int err;
 
 	if ((termios->c_cflag & CSIZE) == CS7) {
 		ccr3_val |= CCR3_CHR0;
@@ -267,25 +266,16 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios,
 	baud = uart_get_baud_rate(port, termios, old, 0, max_freq);
 
 	/* 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 (best_clk >= 0)
-		dev_dbg(port->dev, "Using clk %pC for %u%+d bps\n",
-			s->clks[best_clk], baud, min_err);
+	err = sci_scbrr_calc(s, baud, &brr, &srr, &cks);
+	dev_dbg(port->dev, "Using clk %pC for %u%+d bps\n", s->clks[SCI_FCK],
+		baud, err);
 
 	sci_port_enable(s);
 	uart_port_lock_irqsave(port, &flags);
 
 	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);
@@ -294,7 +284,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);
@@ -315,8 +305,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);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 2/3] serial: sh-sci: Drop check for zero baud rate from uart_get_baud_rate()
  2026-04-20 14:04 ` [PATCH v3 2/3] serial: sh-sci: Drop check for zero baud rate from uart_get_baud_rate() Biju
@ 2026-04-20 15:59   ` Hugo Villeneuve
  2026-04-22  7:04   ` Geert Uytterhoeven
  1 sibling, 0 replies; 10+ messages in thread
From: Hugo Villeneuve @ 2026-04-20 15:59 UTC (permalink / raw)
  To: Biju
  Cc: Greg Kroah-Hartman, Jiri Slaby, Biju Das, Geert Uytterhoeven,
	Lad Prabhakar, Thierry Bultel, linux-kernel, linux-serial,
	linux-renesas-soc

Hi Biju,

On Mon, 20 Apr 2026 15:04:22 +0100
Biju <biju.das.au@gmail.com> wrote:

> From: Biju Das <biju.das.jz@bp.renesas.com>
> 
> On DT systems, a zero baud rate from uart_get_baud_rate() is not possible
> even earlycon derives its bit rate from chosen/stdout-path. The zero baud
> guard and its associated done label are therefore dead code. So remove it.
> 
> Also drop the unused done label from rsci_set_termios().
> 
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>

Acked-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>


> ---
> v3:
>  * New patch
> ---
>  drivers/tty/serial/rsci.c   | 3 ---
>  drivers/tty/serial/sh-sci.c | 2 --
>  2 files changed, 5 deletions(-)
> 
> diff --git a/drivers/tty/serial/rsci.c b/drivers/tty/serial/rsci.c
> index b00c9e385169..40db9daa4272 100644
> --- a/drivers/tty/serial/rsci.c
> +++ b/drivers/tty/serial/rsci.c
> @@ -265,8 +265,6 @@ 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);
> @@ -278,7 +276,6 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios,
>  		cks = cks1;
>  	}
 
> -done:
>  	if (best_clk >= 0)
>  		dev_dbg(port->dev, "Using clk %pC for %u%+d bps\n",
>  			s->clks[best_clk], baud, min_err);
> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> index 7473b26ce9cf..9be359e04995 100644
> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -2719,8 +2719,6 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
>  		max_freq = max(max_freq, s->clk_rates[i]);
>  
>  	baud = uart_get_baud_rate(port, termios, old, 0, max_freq / min_sr(s));
> -	if (!baud)
> -		goto done;
>  
>  	/*
>  	 * There can be multiple sources for the sampling clock.  Find the one
> -- 
> 2.43.0
> 
> 


-- 
Hugo Villeneuve

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH v3 3/3] serial: rsci: Refactor baud rate clock selection
  2026-04-20 14:04 ` [PATCH v3 3/3] serial: rsci: Refactor baud rate clock selection Biju
@ 2026-04-22  6:26   ` Biju Das
  0 siblings, 0 replies; 10+ messages in thread
From: Biju Das @ 2026-04-22  6:26 UTC (permalink / raw)
  To: biju.das.au, Greg Kroah-Hartman, Jiri Slaby
  Cc: Geert Uytterhoeven, Prabhakar Mahadev Lad, Thierry Bultel,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	biju.das.au, linux-renesas-soc@vger.kernel.org

Hi All,

> -----Original Message-----
> From: Biju <biju.das.au@gmail.com>
> Sent: 20 April 2026 15:04
> Subject: [PATCH v3 3/3] serial: rsci: Refactor baud rate clock selection
> 
> From: Biju Das <biju.das.jz@bp.renesas.com>
> 
> 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.
> 
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
> v2->v3:
>  * Dropped reported by tag as the goto statement in rsci_set_termios()
>    removed in the previous patch.
>  * baud check removed by previous patch.
>  * Added missing macro CCR0_RE while dropping ccr0_val variable.
>  * Updated commit description.
> 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 | 31 ++++++++++---------------------
>  1 file changed, 10 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/tty/serial/rsci.c b/drivers/tty/serial/rsci.c index 40db9daa4272..444e89696310
> 100644
> --- a/drivers/tty/serial/rsci.c
> +++ b/drivers/tty/serial/rsci.c
> @@ -217,16 +217,15 @@ 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;

This needs to be initialized to 0. Otherwise it will compare with 
uninitialized stack value on else path.

max_freq = max(max_freq, s->clk_rates[i]);


>  	unsigned int baud, i;
>  	unsigned long flags;
>  	unsigned int ctrl;
> -	int best_clk = -1;
> +	unsigned int srr;

Also, looks this needs to be initialized to 15, when we drop srr1.

sci_scbrr_calc() fails, It will print uninitialized value

Cheers,
Biju



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 2/3] serial: sh-sci: Drop check for zero baud rate from uart_get_baud_rate()
  2026-04-20 14:04 ` [PATCH v3 2/3] serial: sh-sci: Drop check for zero baud rate from uart_get_baud_rate() Biju
  2026-04-20 15:59   ` Hugo Villeneuve
@ 2026-04-22  7:04   ` Geert Uytterhoeven
  2026-04-22  7:26     ` Biju Das
  1 sibling, 1 reply; 10+ messages in thread
From: Geert Uytterhoeven @ 2026-04-22  7:04 UTC (permalink / raw)
  To: Biju
  Cc: Greg Kroah-Hartman, Jiri Slaby, Biju Das, Lad Prabhakar,
	Thierry Bultel, linux-kernel, linux-serial, linux-renesas-soc

Hi Biju,

On Mon, 20 Apr 2026 at 16:04, Biju <biju.das.au@gmail.com> wrote:
> From: Biju Das <biju.das.jz@bp.renesas.com>
>
> On DT systems, a zero baud rate from uart_get_baud_rate() is not possible
> even earlycon derives its bit rate from chosen/stdout-path. The zero baud
> guard and its associated done label are therefore dead code. So remove it.
>
> Also drop the unused done label from rsci_set_termios().
>
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>

Thanks for your patch!

> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -2719,8 +2719,6 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
>                 max_freq = max(max_freq, s->clk_rates[i]);
>
>         baud = uart_get_baud_rate(port, termios, old, 0, max_freq / min_sr(s));
> -       if (!baud)
> -               goto done;
>
>         /*
>          * There can be multiple sources for the sampling clock.  Find the one

I am afraid you are missing that sh-sci is also used on SH, without DT?

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] 10+ messages in thread

* RE: [PATCH v3 2/3] serial: sh-sci: Drop check for zero baud rate from uart_get_baud_rate()
  2026-04-22  7:04   ` Geert Uytterhoeven
@ 2026-04-22  7:26     ` Biju Das
  2026-04-22  8:59       ` Geert Uytterhoeven
  0 siblings, 1 reply; 10+ messages in thread
From: Biju Das @ 2026-04-22  7:26 UTC (permalink / raw)
  To: geert, biju.das.au
  Cc: Greg Kroah-Hartman, Jiri Slaby, Prabhakar Mahadev Lad,
	Thierry Bultel, linux-kernel@vger.kernel.org,
	linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org

Hi Geert,

Thanks for the feedback.

> -----Original Message-----
> From: Geert Uytterhoeven <geert@linux-m68k.org>
> Sent: 22 April 2026 08:05
> Subject: Re: [PATCH v3 2/3] serial: sh-sci: Drop check for zero baud rate from uart_get_baud_rate()
> 
> Hi Biju,
> 
> On Mon, 20 Apr 2026 at 16:04, Biju <biju.das.au@gmail.com> wrote:
> > From: Biju Das <biju.das.jz@bp.renesas.com>
> >
> > On DT systems, a zero baud rate from uart_get_baud_rate() is not
> > possible even earlycon derives its bit rate from chosen/stdout-path.
> > The zero baud guard and its associated done label are therefore dead code. So remove it.
> >
> > Also drop the unused done label from rsci_set_termios().
> >
> > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> 
> Thanks for your patch!
> 
> > --- a/drivers/tty/serial/sh-sci.c
> > +++ b/drivers/tty/serial/sh-sci.c
> > @@ -2719,8 +2719,6 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
> >                 max_freq = max(max_freq, s->clk_rates[i]);
> >
> >         baud = uart_get_baud_rate(port, termios, old, 0, max_freq / min_sr(s));
> > -       if (!baud)
> > -               goto done;
> >
> >         /*
> >          * There can be multiple sources for the sampling clock.  Find
> > the one
> 
> I am afraid you are missing that sh-sci is also used on SH, without DT?

Ok, please share your thoughts to handle divide_by_zero fault for
SH platforms on the code path after done label??

Eg: 
1) uart_update_timeout(port, termios->c_cflag, baud);
2) s->rx_frame = (10000 * bits) / (baud / 100);

Cheers,
Biju



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 2/3] serial: sh-sci: Drop check for zero baud rate from uart_get_baud_rate()
  2026-04-22  7:26     ` Biju Das
@ 2026-04-22  8:59       ` Geert Uytterhoeven
  2026-04-22 14:05         ` Hugo Villeneuve
  0 siblings, 1 reply; 10+ messages in thread
From: Geert Uytterhoeven @ 2026-04-22  8:59 UTC (permalink / raw)
  To: Biju Das
  Cc: biju.das.au, Greg Kroah-Hartman, Jiri Slaby,
	Prabhakar Mahadev Lad, Thierry Bultel,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org

Hi Biju,

On Wed, 22 Apr 2026 at 09:26, Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > From: Geert Uytterhoeven <geert@linux-m68k.org>
> > On Mon, 20 Apr 2026 at 16:04, Biju <biju.das.au@gmail.com> wrote:
> > > From: Biju Das <biju.das.jz@bp.renesas.com>
> > >
> > > On DT systems, a zero baud rate from uart_get_baud_rate() is not
> > > possible even earlycon derives its bit rate from chosen/stdout-path.
> > > The zero baud guard and its associated done label are therefore dead code. So remove it.
> > >
> > > Also drop the unused done label from rsci_set_termios().
> > >
> > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> >
> > > --- a/drivers/tty/serial/sh-sci.c
> > > +++ b/drivers/tty/serial/sh-sci.c
> > > @@ -2719,8 +2719,6 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
> > >                 max_freq = max(max_freq, s->clk_rates[i]);
> > >
> > >         baud = uart_get_baud_rate(port, termios, old, 0, max_freq / min_sr(s));
> > > -       if (!baud)
> > > -               goto done;
> > >
> > >         /*
> > >          * There can be multiple sources for the sampling clock.  Find
> > > the one
> >
> > I am afraid you are missing that sh-sci is also used on SH, without DT?
>
> Ok, please share your thoughts to handle divide_by_zero fault for
> SH platforms on the code path after done label??

Someone has to check on an SH platform (or qemu rts7751r2d) if
this can happen. It might have been broken along the road, as people
only use earlyprintk when debugging a problem that requires it.

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] 10+ messages in thread

* Re: [PATCH v3 2/3] serial: sh-sci: Drop check for zero baud rate from uart_get_baud_rate()
  2026-04-22  8:59       ` Geert Uytterhoeven
@ 2026-04-22 14:05         ` Hugo Villeneuve
  0 siblings, 0 replies; 10+ messages in thread
From: Hugo Villeneuve @ 2026-04-22 14:05 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Biju Das, biju.das.au, Greg Kroah-Hartman, Jiri Slaby,
	Prabhakar Mahadev Lad, Thierry Bultel,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org

Hi,

On Wed, 22 Apr 2026 10:59:23 +0200
Geert Uytterhoeven <geert@linux-m68k.org> wrote:

> Hi Biju,
> 
> On Wed, 22 Apr 2026 at 09:26, Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > > From: Geert Uytterhoeven <geert@linux-m68k.org>
> > > On Mon, 20 Apr 2026 at 16:04, Biju <biju.das.au@gmail.com> wrote:
> > > > From: Biju Das <biju.das.jz@bp.renesas.com>
> > > >
> > > > On DT systems, a zero baud rate from uart_get_baud_rate() is not

The fact that uart_get_baud_rate() cannot return zero is not related
to the system using DT or not, so I would drop this "On DT systems, "
from the commit message.

> > > > possible even earlycon derives its bit rate from chosen/stdout-path.
> > > > The zero baud guard and its associated done label are therefore dead code. So remove it.
> > > >
> > > > Also drop the unused done label from rsci_set_termios().
> > > >
> > > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> > >
> > > > --- a/drivers/tty/serial/sh-sci.c
> > > > +++ b/drivers/tty/serial/sh-sci.c
> > > > @@ -2719,8 +2719,6 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
> > > >                 max_freq = max(max_freq, s->clk_rates[i]);
> > > >
> > > >         baud = uart_get_baud_rate(port, termios, old, 0, max_freq / min_sr(s));
> > > > -       if (!baud)
> > > > -               goto done;
> > > >
> > > >         /*
> > > >          * There can be multiple sources for the sampling clock.  Find
> > > > the one
> > >
> > > I am afraid you are missing that sh-sci is also used on SH, without DT?
> >
> > Ok, please share your thoughts to handle divide_by_zero fault for
> > SH platforms on the code path after done label??
> 
> Someone has to check on an SH platform (or qemu rts7751r2d) if
> this can happen. It might have been broken along the road, as people
> only use earlyprintk when debugging a problem that requires it.

Geert: this "goto done" is not related to the earlyprintk block, which
is untouched by this patch?

-- 
Hugo Villeneuve

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-04-22 14:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-20 14:04 [PATCH v3 0/3] serial: sh-sci/rsci: Fix divide-by-zero and clean up baud rate handling Biju
2026-04-20 14:04 ` [PATCH v3 1/3] serial: sh-sci: Avoid divide-by-zero fault Biju
2026-04-20 14:04 ` [PATCH v3 2/3] serial: sh-sci: Drop check for zero baud rate from uart_get_baud_rate() Biju
2026-04-20 15:59   ` Hugo Villeneuve
2026-04-22  7:04   ` Geert Uytterhoeven
2026-04-22  7:26     ` Biju Das
2026-04-22  8:59       ` Geert Uytterhoeven
2026-04-22 14:05         ` Hugo Villeneuve
2026-04-20 14:04 ` [PATCH v3 3/3] serial: rsci: Refactor baud rate clock selection Biju
2026-04-22  6:26   ` Biju Das

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox