mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] serial: 8250_mtk: correct max baud rate in the set_termios() method
@ 2025-09-05 20:07 Sergey Shtylyov
  2025-09-20  8:56 ` Sergey Shtylyov
  0 siblings, 1 reply; 2+ messages in thread
From: Sergey Shtylyov @ 2025-09-05 20:07 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Matthias Brugger,
	AngeloGioacchino Del Regno, linux-serial, linux-kernel
  Cc: linux-arm-kernel, linux-mediatek

As is obvious from the code calculating the divisor in the set_termios()
method, the Mediatek UART driver uses 256-time oversampling for the high
baud rates, so passing port->uartclk to uart_get_baud_rate() for the max
acceptable baud rate makes no sense, we should divide by 256 first (this
should also prevent overflow when some arbitrary baud rate is passed via
termios->c_ospeed)...

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

Fixes: 81bb549fdf14 ("serial: 8250_mtk: support big baud rate.")
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>

---
The patch is against the master branch of Linus Torvalds' linux.git repo.

 drivers/tty/serial/8250/8250_mtk.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux/drivers/tty/serial/8250/8250_mtk.c
===================================================================
--- linux.orig/drivers/tty/serial/8250/8250_mtk.c
+++ 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);
+				  port->uartclk / 256);
 
 	if (baud < 115200) {
 		serial_port_out(port, MTK_UART_HIGHS, 0x0);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] serial: 8250_mtk: correct max baud rate in the set_termios() method
  2025-09-05 20:07 [PATCH] serial: 8250_mtk: correct max baud rate in the set_termios() method Sergey Shtylyov
@ 2025-09-20  8:56 ` Sergey Shtylyov
  0 siblings, 0 replies; 2+ messages in thread
From: Sergey Shtylyov @ 2025-09-20  8:56 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Matthias Brugger,
	AngeloGioacchino Del Regno, linux-serial, linux-kernel

On 9/5/25 11:07 PM, Sergey Shtylyov wrote:

> As is obvious from the code calculating the divisor in the set_termios()
> method, the Mediatek UART driver uses 256-time oversampling for the high
> baud rates, so passing port->uartclk to uart_get_baud_rate() for the max
> acceptable baud rate makes no sense, we should divide by 256 first (this

   Well, I thought again and 256 seems to be an overkill, I should probably
have reverted to division by 16 instead...

> should also prevent overflow when some arbitrary baud rate is passed via
> termios->c_ospeed)...
> 
> Found by Linux Verification Center (linuxtesting.org) with the Svace static
> analysis tool.
> 
> Fixes: 81bb549fdf14 ("serial: 8250_mtk: support big baud rate.")
> Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>

[...]

MBR, Sergey


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-20  8:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-05 20:07 [PATCH] serial: 8250_mtk: correct max baud rate in the set_termios() method Sergey Shtylyov
2025-09-20  8:56 ` Sergey Shtylyov

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®