From: Hugo Villeneuve <hugo@hugovil.com>
To: gregkh@linuxfoundation.org, jirislaby@kernel.org, alan@linux.intel.com
Cc: hugo@hugovil.com, gregkh@suse.de, linux-kernel@vger.kernel.org,
linux-serial@vger.kernel.org,
Hugo Villeneuve <hvilleneuve@dimonoff.com>
Subject: [PATCH 0/5] serial: core: fixes and improvements to uart_get_baud_rate()
Date: Tue, 20 Oct 2026 14:41:16 -0400 [thread overview]
Message-ID: <20261020184131.2893575-1-hugo@hugovil.com> (raw)
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
next reply other threads:[~2026-10-20 18:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 18:41 Hugo Villeneuve [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261020184131.2893575-1-hugo@hugovil.com \
--to=hugo@hugovil.com \
--cc=alan@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=gregkh@suse.de \
--cc=hvilleneuve@dimonoff.com \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®