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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux