mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/5] serial: core: fixes and improvements to uart_get_baud_rate()
@ 2026-10-20 18:41 Hugo Villeneuve
  2026-10-20 18:41 ` [PATCH 1/5] serial: core: fix division by zero if old termios is present but has invalid rate Hugo Villeneuve
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Hugo Villeneuve @ 2026-10-20 18:41 UTC (permalink / raw)
  To: gregkh, jirislaby, alan
  Cc: hugo, gregkh, linux-kernel, linux-serial, Hugo Villeneuve

From: Hugo Villeneuve <hvilleneuve@dimonoff.com>

serial: core: fixes and improvements to uart_get_baud_rate()

Hello,
this patch series brings fixes and improvements to uart_get_baud_rate()

This is in part based on discussions following Hui patches submission [1]
to fix a divide by zero fault originating from uart_get_baud_rate().

Patch 1 is the fix for the above mentioned bug, as suggested by Hui
but with much improved comments, bug report and reproduce steps so that is is
easier to follow and understand. In original discussion, it was suggested by
Ilpo and me that when rate gets lowered, it should alter the termios to prevent
what is here seem as "old" having an invalid value. This is not handled by this
series at the moment, as this may be more complex than anticipated.

Patch 2 is another fix for a potential divide by zero scenario.

Patch 3 removes any possibility for the function to return zero baud rate
if the loop exits without a valid baud rate. History has shown that for
this function, there was often unforeseen or unanticipated conditions
that made the loop exit unexpectedly with a zero baud rate.

Patch 4 is a small improvement in readability to avoid a redundant baud
assignment without any UPF_SPD_* flags. It could be merged with the refactor
patch if deemed appropriate.

Patch 5 is a refactoring of uart_get_baud_rate() to make it easier to
understand and analyze, and more linear, as with the current loop is is
sometimes not easy to fully grasp what is happening. But in the end, I
am not sure it is worth it as the loop makes things more efficient and
simpler. I include the patch for discussion, but it may be removed from
this series.

Tested the changes on a custom board with imx uart and two SC16IS752 DUART
over a SPI interface using a Variscite IMX6 SOM.

Link: https://lore.kernel.org/all/20260930125901.778868-1-benquike@gmail.com/ [1]

Thank you.

Hugo Villeneuve (5):
  serial: core: fix division by zero if old termios is present but has
    invalid rate
  serial: core: clip out-of-range baud rate to min/max, not min+1/max-1
  serial: core: always return in-range baud rate even in case of failure
  serial: core: avoid redundant baud assignment without any UPF_SPD_*
    flags
  serial: core: refactor uart_get_baud_rate() for readability

 drivers/tty/serial/serial_core.c | 113 ++++++++++++++++++-------------
 1 file changed, 65 insertions(+), 48 deletions(-)


base-commit: 1184f87e2790e8af9be3116f608d2e86b4792d7d
-- 
2.47.3


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

end of thread, other threads:[~2026-10-20 18:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-20 18:41 [PATCH 0/5] serial: core: fixes and improvements to uart_get_baud_rate() Hugo Villeneuve
2026-10-20 18:41 ` [PATCH 1/5] serial: core: fix division by zero if old termios is present but has invalid rate Hugo Villeneuve
2026-10-20 18:41 ` [PATCH 2/5] serial: core: clip out-of-range baud rate to min/max, not min+1/max-1 Hugo Villeneuve
2026-10-20 18:41 ` [PATCH 3/5] serial: core: always return in-range baud rate even in case of failure Hugo Villeneuve
2026-10-20 18:41 ` [PATCH 4/5] serial: core: avoid redundant baud assignment without any UPF_SPD_* flags Hugo Villeneuve
2026-10-20 18:41 ` [PATCH 5/5] serial: core: refactor uart_get_baud_rate() for readability Hugo Villeneuve

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®