libusbclient/stm32n6: fix interrupt handler races#650
Conversation
TASK: PP-403
713816b to
e3e4844
Compare
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Code Review
This pull request introduces atomic operations for interrupt handling in the STM32N6 USB client driver. Key changes include converting pending_event, irqPendingDIEPINT, and irqPendingDOEPINT to _Atomic types and using atomic_exchange to safely retrieve and clear pending flags in a single operation. As a result, ctrl_lifiq_handler has been updated to accept the interrupt status by value, and manual bit-clearing logic within the interrupt handlers has been removed to simplify the code and improve thread safety. I have no feedback to provide.
| _Atomic uint32_t daintClear; | ||
| uint32_t irqPendingDIEPINT[ENDPOINTS_NUMBER]; | ||
| uint32_t irqPendingDOEPINT[ENDPOINTS_NUMBER]; | ||
| _Atomic uint32_t irqPendingDIEPINT[ENDPOINTS_NUMBER]; |
There was a problem hiding this comment.
Maybe use the atomic_uint type from stdatomic.h instead? It's best to avoid using attributes that start with with underscores directly.
There was a problem hiding this comment.
I just wanted to clearly communicate the intention that "this must be a 32bit unsigned integer", since it reflects the value of hw registers. Obviously atomic_uint will be the exact same type since unsigned int is 32bit on pretty much every sensible platform but I just wasn't sure if the intention is clear enough that way.
From my understanding the main problem with using _Atomic is that it breaks compatibility with C++ since C++ uses std::atomic<T> instead of _Atomic. I'm not sure how much of an issue that is for us.
Anyway, I'm ok with changing it but I just wanted to express my thoughts and hear what you have to say before committing the change blindly.
TASK: PP-403
Description
This change fixes potential read-modify-write races inside the low frequency interrupt handler
Motivation and Context
Types of changes
How Has This Been Tested?
Checklist:
Special treatment