From 1a541ef95801e4159a57cc057c8ea82428aae88c Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 9 Feb 2021 11:34:26 -0600 Subject: [PATCH] ASoC: da7219-aad: fix possible race condition in interrupt When the irq_thread deals with jack removal, it modifies DAPM pin states and then wait for workqueues to complete. The problem is that those workqueues also modify DAPM pin states, and the DAPM pin states may be inconsistent. This patch suggests first waiting for scheduled workqueues to complete before changing the DAPM pin states. Signed-off-by: Pierre-Louis Bossart --- sound/soc/codecs/da7219-aad.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/da7219-aad.c b/sound/soc/codecs/da7219-aad.c index 48081d71c22c93d..3229e13366dd928 100644 --- a/sound/soc/codecs/da7219-aad.c +++ b/sound/soc/codecs/da7219-aad.c @@ -424,6 +424,11 @@ static irqreturn_t da7219_aad_irq_thread(int irq, void *data) } else { /* Jack removal */ if (events[DA7219_AAD_IRQ_REG_A] & DA7219_E_JACK_REMOVED_MASK) { + + /* Cancel any pending work */ + cancel_work_sync(&da7219_aad->btn_det_work); + cancel_work_sync(&da7219_aad->hptest_work); + report = 0; mask |= DA7219_AAD_REPORT_ALL_MASK; da7219_aad->jack_inserted = false; @@ -443,10 +448,6 @@ static irqreturn_t da7219_aad_irq_thread(int irq, void *data) /* Disable mic bias */ snd_soc_dapm_disable_pin(dapm, "Mic Bias"); snd_soc_dapm_sync(dapm); - - /* Cancel any pending work */ - cancel_work_sync(&da7219_aad->btn_det_work); - cancel_work_sync(&da7219_aad->hptest_work); } }