[PATCH 17/24] serial: stm32: bail if clock_get_rate returns zero

Ahmad Fatoum a.fatoum at pengutronix.de
Sun Feb 20 04:47:29 PST 2022


While this shouldn't happen in a well-behaving system, with SCMI barebox
may become dependent on the firmware to provide a non-zero rate here.

Sanitize the value to avoid a division -by-zero.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/serial/serial_stm32.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/serial/serial_stm32.c b/drivers/serial/serial_stm32.c
index 271897f1743c..f1d4c6de9074 100644
--- a/drivers/serial/serial_stm32.c
+++ b/drivers/serial/serial_stm32.c
@@ -41,6 +41,8 @@ static int stm32_serial_setbaudrate(struct console_device *cdev, int baudrate)
 	unsigned long clock_rate;
 
 	clock_rate = clk_get_rate(stm32->clk);
+	if (!clock_rate)
+		return -EINVAL;
 
 	int_div = DIV_ROUND_CLOSEST(clock_rate, baudrate);
 
-- 
2.30.2




More information about the barebox mailing list