Skip to content

serial: core: fixes and improvements to uart_get_baud_rate()

Hugo Villeneuve linux-serial lkml stable 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5serial: core: fix division by zero if old termios is present but has invalid ratedrivers/tty/serial/serial_core.c+4 -70 replies
2/5serial: core: clip out-of-range baud rate to min/max, not min+1/max-1drivers/tty/serial/serial_core.c+3 -30 replies
3/5serial: core: always return in-range baud rate even in case of failuredrivers/tty/serial/serial_core.c+3 -20 replies
4/5serial: core: avoid redundant baud assignment without any UPF_SPD_* flagsdrivers/tty/serial/serial_core.c+4 -20 replies
5/5serial: core: refactor uart_get_baud_rate() for readabilitydrivers/tty/serial/serial_core.c+60 -430 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/5] serial: core: fixes and improvements to uart_get_baud_rate()

From: Hugo Villeneuve <[email protected]>

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.

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

Signature · 1 line
2.47.3