-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cpu/stm32/periph/timer: prevent spurious IRQs #20926
cpu/stm32/periph/timer: prevent spurious IRQs #20926
Conversation
This patch hardens the STM32 timer driver against some possible causes of spurious IRQs.
hmm I'm not convinced - what makes you think the current code is incorrect then? |
The first change in The second change in Both changes are intended to prevent situations like following (nonsense) example: int *ptr = NULL;
void timer_callback(int channel)
{
*ptr++;
}
void func(void)
{
int val = 0;
ptr = &val;
timer_set(timer, 0, 100);
// do some stuff
const irq_state = irq_disable()
timer_clear(timer, 0); /* or */ timer_set(timer, 0, 999999);
// at this point, callers will expect that the timer will not fire, or fire at some point way in the future
ptr = NULL
irq_restore(irq_state);
// once we leave the critical section, spurious timer IRQ fires and NULL is dereferenced
ptr = &val;
} |
Ok sounds reasonable. |
Done. |
Contribution description
This patch hardens the STM32 timer driver against some possible causes of spurious IRQs.
I did not actually observe spurious IRQs happening, but this PR comes as the result of a deep dive into the timer code to solve the bug in #20924. This PR is a defensive measure only.
Testing procedure
Timers should continue to work.
Issues/PRs references