From: Mikko Perttunen <mperttunen@nvidia.com>
To: Laxman Dewangan <ldewangan@nvidia.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>,
Thierry Reding <thierry.reding@kernel.org>,
Jonathan Hunter <jonathanh@nvidia.com>,
stable@vger.kernel.org
Cc: Shardar Shariff Md <smohammed@nvidia.com>,
Krishna Yarlagadda <kyarlagadda@nvidia.com>,
Svyatoslav Ryhel <clamor95@gmail.com>,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
linux-tegra@vger.kernel.org, stable@vger.kernel.org,
Patrick Fischer <admin@tsv-stahl-riesa.de>,
admin@tsv-stahl-riesa.de
Subject: Re: [PATCH 1/2] serial: tegra: Fix overflow in tegra_get_tolerance_rate()
Date: Thu, 26 Nov 2026 16:42:10 +0900 [thread overview]
Message-ID: <GC5VPrgKRqiMtmL3TGQ-nA@nvidia.com> (raw)
In-Reply-To: <20261025-upstream-serial-tegra-overflow-v1-1-267b5b7a79ee@tsv-stahl-riesa.de>
On Monday, October 26, 2026 7:50 AM Patrick Fischer via B4 Relay wrote:
> From: Patrick Fischer <admin@tsv-stahl-riesa.de>
>
> tegra_get_tolerance_rate() raises or lowers the UART clock rate by the
> tolerance from "nvidia,adjust-baud-rates", given in units of 0.01 %. It
> calculates rate * tolerance in a long, which is only 32 bits wide on
> 32-bit ARM. With a tolerance of 136 this overflows from a clock rate of
> about 15.8 MHz, i.e. from about 1 Mbaud, and the rate ends up adjusted
> in the wrong direction.
>
> The Tegra Note 7 (Tegra114) uses a tolerance of 136 for 1 to 4 Mbaud on
> its Bluetooth UART, as in the downstream device tree. For 3 Mbaud the
> driver asks for 47.79 MHz instead of 48.65 MHz, the clock rounds that
> down to 408 MHz / 9 = 45.33 MHz (-5.6 %), and the WL1801 controller
> stops answering after the switch to 3 Mbaud (HCI commands time out
> with -110). The same overflow gives 23.31 MHz instead of 24 MHz at
> 1.5 Mbaud; both rates were confirmed on the device.
>
> Do the multiplication in 64 bits. With that the driver asks for
> 48.65 MHz at 3 Mbaud and gets 48.00 MHz.
>
> Tested on the Tegra Note 7 with the tolerance of 136: Bluetooth comes
> up at 3 Mbaud, scans and connects to a paired device, and the HCI
> counters show no errors.
>
> 64-bit platforms are not affected.
>
> Fixes: f04a3cc8d455 ("serial: tegra: add support to adjust baud rate")
> Cc: stable@vger.kernel.org
> Signed-off-by: Patrick Fischer <admin@tsv-stahl-riesa.de>
> ---
> drivers/tty/serial/serial-tegra.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/tty/serial/serial-tegra.c b/drivers/tty/serial/serial-tegra.c
> index b0fc4ae3686f..cc09fbc3aad8 100644
> --- a/drivers/tty/serial/serial-tegra.c
> +++ b/drivers/tty/serial/serial-tegra.c
> @@ -18,6 +18,7 @@
> #include <linux/err.h>
> #include <linux/io.h>
> #include <linux/irq.h>
> +#include <linux/math64.h>
> #include <linux/module.h>
> #include <linux/of.h>
> #include <linux/pagemap.h>
> @@ -368,8 +369,8 @@ static long tegra_get_tolerance_rate(struct tegra_uart_port *tup,
> for (i = 0; i < tup->n_adjustable_baud_rates; ++i) {
> if (baud >= tup->baud_tolerance[i].lower_range_baud &&
> baud <= tup->baud_tolerance[i].upper_range_baud)
> - return (rate + (rate *
> - tup->baud_tolerance[i].tolerance) / 10000);
> + return rate + div_s64((s64)rate *
> + tup->baud_tolerance[i].tolerance, 10000);
> }
>
> return rate;
>
> --
> 2.56.0
>
>
>
Reviewed-by: Mikko Perttunen <mperttunen@nvidia.com>
next prev parent reply other threads:[~2026-11-26 7:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-25 22:50 [PATCH 0/2] serial: tegra: Fix 32-bit overflows in the clock rate adjustment Patrick Fischer via B4 Relay
2026-10-25 22:50 ` [PATCH 1/2] serial: tegra: Fix overflow in tegra_get_tolerance_rate() Patrick Fischer via B4 Relay
2026-10-25 23:13 ` sashiko-bot
2026-10-26 8:50 ` Svyatoslav Ryhel
2026-11-26 7:42 ` Mikko Perttunen [this message]
2026-10-25 22:50 ` [PATCH 2/2] serial: tegra: Fix overflow in tegra_check_rate_in_range() Patrick Fischer via B4 Relay
2026-10-25 23:08 ` sashiko-bot
2026-10-26 8:50 ` Svyatoslav Ryhel
2026-11-26 7:43 ` Mikko Perttunen
2026-11-22 9:42 ` [PATCH 0/2] serial: tegra: Fix 32-bit overflows in the clock rate adjustment Patrick Fischer
2026-11-22 9:46 ` Greg Kroah-Hartman
2026-11-22 10:13 ` Patrick Fischer
2026-11-22 11:03 ` Greg Kroah-Hartman
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=GC5VPrgKRqiMtmL3TGQ-nA@nvidia.com \
--to=mperttunen@nvidia.com \
--cc=admin@tsv-stahl-riesa.de \
--cc=clamor95@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=jonathanh@nvidia.com \
--cc=kyarlagadda@nvidia.com \
--cc=ldewangan@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=smohammed@nvidia.com \
--cc=stable@vger.kernel.org \
--cc=thierry.reding@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