core: Warn about using irq_enable #17433
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contribution description
Setting the system in a state with more interrupts enabled than expected by the caller is generally unexpected -- if this were allowed unchecked, many components would need to revisit and tighten their synchronization efforts making them less efficient. (I didn't do a precise check, but I expect that ztimer might not tolerate interrupts to be enabled by the callback, especially as that means that unrelated interrupts might manipulate ztimer again).
One offending user was found in the implementations (motor_driver) and changed to use irq_restore. All others have some justification for using enable (eg. it's done in an ISR).
Testing procedure
Issues/PRs references
This came up looking at the synchronization necessary around Rust code. If arbitrary callbacks can enable interrupts just like that without responsibility, code in critical sections just needs way more severe locking and precautions.
[edit: since when does GitHub accept submissions with plain Enter? Sucks...]