Re: [PATCH 0/5] serial: core: fixes and improvements to uart_get_baud_rate()
From: Hugo Villeneuve
Date: Wed Nov 04 2026 - 11:11:01 EST
On Tue, 20 Oct 2026 14:41:16 -0400
Hugo Villeneuve <hugo@xxxxxxxxxxx> wrote:
> From: Hugo Villeneuve <hvilleneuve@xxxxxxxxxxxx>
>
> 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@xxxxxxxxx/ [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(-)
Hi,
I think this series has some implications for Maciej series "Don't
clobber the baud rate on hangup via B0" [1], so this is a small
ping...
https://lore.kernel.org/all/alpine.DEB.2.21.2611030057510.15685@xxxxxxxxxxxxxxxxx/raw
[1]
--
Hugo Villeneuve