Skip to content

Commit 1280e98

Browse files
FRASTMnashif
authored andcommitted
drivers: timer: stm32 lptim fix Potentially overflow
Fix Unintentional integer overflow in the calculation Integer handling issues (OVERFLOW_BEFORE_WIDEN) Potentially overflowing expression Signed-off-by: Francois Ramu <[email protected]>
1 parent 7712caa commit 1280e98

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/timer/stm32_lptim_timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ uint32_t z_clock_elapsed(void)
291291
/* gives the value of LPTIM1 counter (ms)
292292
* since the previous 'announce'
293293
*/
294-
uint64_t ret = (lp_time * CONFIG_SYS_CLOCK_TICKS_PER_SEC) / LPTIM_CLOCK;
294+
uint64_t ret = ((uint64_t)lp_time * CONFIG_SYS_CLOCK_TICKS_PER_SEC) / LPTIM_CLOCK;
295295

296296
return (uint32_t)(ret);
297297
}
@@ -315,7 +315,7 @@ uint32_t z_timer_cycle_get_32(void)
315315
lp_time += accumulated_lptim_cnt;
316316

317317
/* convert lptim count in a nb of hw cycles with precision */
318-
uint64_t ret = lp_time * (sys_clock_hw_cycles_per_sec() / LPTIM_CLOCK);
318+
uint64_t ret = ((uint64_t)lp_time * sys_clock_hw_cycles_per_sec()) / LPTIM_CLOCK;
319319

320320
k_spin_unlock(&lock, key);
321321

0 commit comments

Comments
 (0)