Skip to content

Commit 8b391dc

Browse files
ananglcarlescufi
authored andcommitted
drivers: audio: dmic_nrfx_pdm: Fix a race condition in the driver
When the PAUSE or STOP command was triggered, the driver was first requesting the PDM peripheral to stop by calling nrfx_pdm_stop() and then it was setting a flag that was in turn checked in an interrupt that was generated when the PDM actually stopped (what happens a moment after the stop request is made). But that setting of the flag could get preempted and the interrupt handler could get executed first causing the stopping to be not handled properly and leaving the driver falsely considering the peripheral as still active. This commit reverses the order of these two operations to avoid the described race condition. Same sequence is corrected also in event_handler(), but this is done only for consistency (it is in the interrupt handler itself so there is no race possible in this case). Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent e326c58 commit 8b391dc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/audio/dmic_nrfx_pdm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ static void event_handler(const struct device *dev, const nrfx_pdm_evt_t *evt)
9595
}
9696

9797
if (stop) {
98-
nrfx_pdm_stop();
9998
drv_data->stopping = true;
99+
nrfx_pdm_stop();
100100
}
101101
}
102102

@@ -461,8 +461,8 @@ static int dmic_nrfx_pdm_trigger(const struct device *dev,
461461
case DMIC_TRIGGER_PAUSE:
462462
case DMIC_TRIGGER_STOP:
463463
if (drv_data->active) {
464-
nrfx_pdm_stop();
465464
drv_data->stopping = true;
465+
nrfx_pdm_stop();
466466
}
467467
break;
468468

0 commit comments

Comments
 (0)