From 1cbb1cc911dedc75247e53b672843139ae9b8b31 Mon Sep 17 00:00:00 2001 From: Stephan Linz Date: Mon, 9 Oct 2023 10:25:11 +0200 Subject: [PATCH] drivers: can: avoid integer overflow in expression Change the integer arithmetic to divide first before multiply. The muliplication of sys_clock_hw_cycles_per_sec() by ten leads to a really big number on boards with high-speed clocking, thus to the overflow warning, and to errors for integration tests. (cherry picked from commit e7f399f4a3216d2e86b95683f476eb9d2cc871da) Original-Fixes: #63678 Original-Signed-off-by: Stephan Linz GitOrigin-RevId: e7f399f4a3216d2e86b95683f476eb9d2cc871da Change-Id: I232c13d4b396209a5adae9b21120a0154853bae1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/4921894 Reviewed-by: Keith Short Tested-by: Keith Short Commit-Queue: Keith Short Tested-by: ChromeOS Prod (Robot) --- drivers/can/can_stm32_bxcan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/can/can_stm32_bxcan.c b/drivers/can/can_stm32_bxcan.c index abae476e7d1..9ded24233d2 100644 --- a/drivers/can/can_stm32_bxcan.c +++ b/drivers/can/can_stm32_bxcan.c @@ -21,7 +21,7 @@ LOG_MODULE_REGISTER(can_stm32, CONFIG_CAN_LOG_LEVEL); -#define CAN_INIT_TIMEOUT (10 * sys_clock_hw_cycles_per_sec() / MSEC_PER_SEC) +#define CAN_INIT_TIMEOUT (10 * (sys_clock_hw_cycles_per_sec() / MSEC_PER_SEC)) #define DT_DRV_COMPAT st_stm32_bxcan