Skip to content

Commit a6d7866

Browse files
kv2019ibroonie
authored andcommitted
ASoC: rt5668: do not block workqueue if card is unbound
The current rt5668_jack_detect_handler() assumes the component and card will always show up and implements an infinite usleep loop waiting for them to show up. This does not hold true if a codec interrupt (or other event) occurs when the card is unbound. The codec driver's remove or shutdown functions cannot cancel the workqueue due to the wait loop. As a result, code can either end up blocking the workqueue, or hit a kernel oops when the card is freed. Fix the issue by rescheduling the jack detect handler in case the card is not ready. In case card never shows up, the shutdown/remove/suspend calls can now cancel the detect task. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com> Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com> Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com> Reviewed-by: Shuming Fan <shumingf@realtek.com> Link: https://lore.kernel.org/r/20220207153000.3452802-2-kai.vehmanen@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent d7b530f commit a6d7866

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

sound/soc/codecs/rt5668.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,11 +1022,13 @@ static void rt5668_jack_detect_handler(struct work_struct *work)
10221022
container_of(work, struct rt5668_priv, jack_detect_work.work);
10231023
int val, btn_type;
10241024

1025-
while (!rt5668->component)
1026-
usleep_range(10000, 15000);
1027-
1028-
while (!rt5668->component->card->instantiated)
1029-
usleep_range(10000, 15000);
1025+
if (!rt5668->component || !rt5668->component->card ||
1026+
!rt5668->component->card->instantiated) {
1027+
/* card not yet ready, try later */
1028+
mod_delayed_work(system_power_efficient_wq,
1029+
&rt5668->jack_detect_work, msecs_to_jiffies(15));
1030+
return;
1031+
}
10301032

10311033
mutex_lock(&rt5668->calibrate_mutex);
10321034

0 commit comments

Comments
 (0)