RE: [PATCH v3 3/3] serial: rsci: Refactor baud rate clock selection
From: Biju Das
Date: Wed Apr 22 2026 - 02:29:56 EST
Hi All,
> -----Original Message-----
> From: Biju <biju.das.au@xxxxxxxxx>
> Sent: 20 April 2026 15:04
> Subject: [PATCH v3 3/3] serial: rsci: Refactor baud rate clock selection
>
> From: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
>
> 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@xxxxxxxxxxxxxx>
> ---
> 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