Skip to content

Commit f9b40d4

Browse files
authored
Merge pull request #5364 from osresearch/delay-overflow
mp_hal_delay_ms: avoid overflow when scaling ticks
2 parents f5ef255 + 4ab00d7 commit f9b40d4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

supervisor/shared/tick.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ void PLACE_IN_ITCM(supervisor_run_background_tasks_if_tick)() {
127127
background_callback_run_all();
128128
}
129129

130-
void mp_hal_delay_ms(mp_uint_t delay) {
130+
void mp_hal_delay_ms(mp_uint_t delay_ms) {
131131
uint64_t start_tick = port_get_raw_ticks(NULL);
132132
// Adjust the delay to ticks vs ms.
133-
delay = delay * 1024 / 1000;
134-
uint64_t end_tick = start_tick + delay;
135-
int64_t remaining = delay;
133+
uint64_t delay_ticks = (delay_ms * (uint64_t)1024) / 1000;
134+
uint64_t end_tick = start_tick + delay_ticks;
135+
int64_t remaining = delay_ticks;
136136

137137
// Loop until we've waited long enough or we've been CTRL-Ced by autoreload
138138
// or the user.

0 commit comments

Comments
 (0)