nxp-mcuxpresso / mcux-sdk

MCUXpresso SDK
BSD 3-Clause "New" or "Revised" License
301 stars 136 forks source link

drivers: fsl_dma: Fix incorrect access of common registers #174

Closed JonathonReinhart closed 4 months ago

JonathonReinhart commented 4 months ago

Prerequisites

Describe the pull request The SET and CLR peripheral registers will set and clear bits in the underlying register without requiring a racy read-modify-write sequence. ABORT is write-only and has essentially the same semantics.

The current code using |= defeats this safety and in a multithreaded environment, this could inadvetently set bits which were recently cleared by another thread.

Replace the use of DMA_COMMON_REG_GET(...) |= 1 << x with DMA_COMMON_REG_SET(..., | 1 << x) to only write a 1 to the desired bit, leaving all others alone.

Fixes: #173

Type of change

Tests TBD

JonathonReinhart commented 4 months ago

I've tested this in the target application and verified there are no obvious regressions. I haven't yet done any targeted tests on the EVK.