[PATCH RFC 1/4] serial: esp32: Validate the baud rate before programming the UART
Vítor Hugo Silva
vitorhg20080 at gmail.com
Fri Nov 27 08:55:49 PST 2026
Early console setup can reach esp32_uart_set_baud() with no baud rate
or clock rate. Reject rates that cannot produce a valid divider
before dividing or writing the UART registers. Early console output
can continue with the firmware configuration in this case.
A mocked register test verified that a zero baud or clock rate leaves
the registers untouched.
Signed-off-by: Vítor Hugo Silva <vitorhg20080 at gmail.com>
---
This series addresses five findings from the review of patch 10/19
and applies after patch 11/19 of the ESP32-P4 RFC.
drivers/tty/serial/esp32_uart.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/esp32_uart.c b/drivers/tty/serial/esp32_uart.c
index 304e134..895d0ec 100644
--- a/drivers/tty/serial/esp32_uart.c
+++ b/drivers/tty/serial/esp32_uart.c
@@ -448,7 +448,12 @@ static void esp32_uart_shutdown(struct uart_port *port)
static bool esp32_uart_set_baud(struct uart_port *port, u32 baud)
{
u32 sclk = port->uartclk;
- u32 div = sclk / baud;
+ u32 div;
+
+ if (!baud || baud > sclk)
+ return false;
+
+ div = sclk / baud;
if (port_variant(port)->has_clkconf) {
u32 sclk_div = div / port_variant(port)->clkdiv_mask;
More information about the linux-riscv
mailing list