Skip to contentSkip to conversation

serial: 8250_mtk: correct max baud rate in set_termios() method

PATCH Superseded Sergey Shtylyov 2 participants 3 messages Oct 12, 2025 – Oct 14, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 serial: 8250_mtk: correct max baud rate in set_termios() method

Mediatek MT798x datasheets (that I was able to get my hands on) claim the maximum supported baud rate to be 3 Mbps, while commit 81bb549fdf14 ("serial: 8250_mtk: support big baud rate.") claimed it to be 4 Mbps -- however, it then passed undivided port->uartclk to uart_get_baud_rate() for the maximum baud rate, while the datasheets do mention up to 52 MHz as the baud clock's frequency. This means that an integer overflow will happen (when multiplying the baud variable by 256) if a baud rate higher than 16777215 bps is passed via termios->c_ospeed. Pass the correct max baud rate of 3 Mbps or port->uartclk, whichever happens to be less...

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Fixes 81bb549fdf14 ("serial: 8250_mtk: support big baud rate.")

---
The patch is against the master branch of Linus Torvalds' linux.git repo (I'm unable to use the other repos on git.kernel.org and I have to update Linus' repo from GitHub).

Changes in version 2:
- changed the approach to the problem (and hence rewrote the description);
- removed "the" article from the subject for brevity.

 drivers/tty/serial/8250/8250_mtk.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/8250/8250_mtk.c +1 -1
Index: linux/drivers/tty/serial/8250/8250_mtk.c
===================================================================
@@ -358,7 +358,7 @@ mtk8250_set_termios(struct uart_port *po
 	 */
 	baud = uart_get_baud_rate(port, termios, old,
 				  port->uartclk / 16 / UART_DIV_MAX,
-				  port->uartclk);
+				  min(3000000U, port->uartclk));
 
 	if (baud < 115200) {
 		serial_port_out(port, MTK_UART_HIGHS, 0x0);
#1 lore raw
Quoted 3 lines · Sergey Shtylyov

Mediatek MT798x datasheets (that I was able to get my hands on) claim the maximum supported baud rate to be 3 Mbps, while commit 81bb549fdf14 ("serial: 8250_mtk: support big baud rate.") claimed it to be 4 Mbps --

At least MT7987A datasheet claims to support up to 4 Mbps, so I think 4 Mbps should be chosen for the upper limit.

+ added the authors of 81bb549fdf14 ("serial: 8250_mtk: support big baud rate.") to Cc.

--
Fedor

#2 lore raw
Quoted 1 line · Fedor Pchelkin
Quoted 1 line

Mediatek MT798x datasheets (that I was able to get my hands on) claim

Thank you, Fedor, BTW! :-)

Quoted 5 lines
Quoted 2 lines

the maximum supported baud rate to be 3 Mbps, while commit 81bb549fdf14 ("serial: 8250_mtk: support big baud rate.") claimed it to be 4 Mbps --

At least MT7987A datasheet claims to support up to 4 Mbps, so I think 4 Mbps should be chosen for the upper limit.

FTR, this SoC doesn't seem to be supported by the mainline kernel (looking
at Linus' repo, at least).
I think, we should "parametrize" the max (and maybe even min?) baud rate
adding more specific compatibles to mtk8250_of_match[] (and probably setting this parameter to 4 Mbps for the existing entry)...

Quoted 2 lines

+ added the authors of 81bb549fdf14 ("serial: 8250_mtk: support big baud rate.") to Cc.

Just noticed that the author of this "wonderful" patch didn't even sign off
on it. "Excellent" work! :-/

Quoted 2 lines

--
Fedor

MBR, Sergey