[PATCH v6 2/3] serial: core: fix baud rate fallback in uart_get_baud_rate()
From: Hui Peng
Date: Wed Sep 30 2026 - 03:49:36 EST
In uart_get_baud_rate(), when a custom divisor is requested, if
port->uartclk is zero, the fallback logic evaluates baud = port->uartclk / 16
which results in baud = 0, causing a divide-by-zero error in subsequent
calculations.
Ensure uart_get_baud_rate() falls back to a valid default baud rate when
port->uartclk is zero.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@xxxxxxxxxxxxxxx
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@xxxxxxxxx>
---
drivers/tty/serial/serial_core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 95774b0f1484..55bb1eaa27e7 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -480,6 +480,11 @@ uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
return 0;
max = port->uartclk / 16;
+ if (!max)
+ max = 115200;
+
if (termios) {
baud = tty_termios_baud_rate(termios);