[PATCH v2 0/2] serial: sh-sci/rsci: Fix divide by zero and clean up baud rate logic

Biju posted 2 patches 2 months, 1 week ago
drivers/tty/serial/rsci.c   | 36 +++++++++++++-----------------------
drivers/tty/serial/sh-sci.c |  3 ++-
2 files changed, 15 insertions(+), 24 deletions(-)
[PATCH v2 0/2] serial: sh-sci/rsci: Fix divide by zero and clean up baud rate logic
Posted by Biju 2 months, 1 week ago
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