[PATCH v3 0/3] serial: sh-sci/rsci: Fix divide-by-zero and clean up baud rate handling
From: Biju
Date: Mon Apr 20 2026 - 11:03:11 EST
From: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
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