Skip to content

Commit 2b490e1

Browse files
kv2019igregkh
authored andcommitted
ASoC: rt5682: do not block workqueue if card is unbound
[ Upstream commit 4c33de0 ] The current rt5682_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-3-kai.vehmanen@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 2bbe041 commit 2b490e1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

sound/soc/codecs/rt5682.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,11 +1092,13 @@ void rt5682_jack_detect_handler(struct work_struct *work)
10921092
struct snd_soc_dapm_context *dapm;
10931093
int val, btn_type;
10941094

1095-
while (!rt5682->component)
1096-
usleep_range(10000, 15000);
1097-
1098-
while (!rt5682->component->card->instantiated)
1099-
usleep_range(10000, 15000);
1095+
if (!rt5682->component || !rt5682->component->card ||
1096+
!rt5682->component->card->instantiated) {
1097+
/* card not yet ready, try later */
1098+
mod_delayed_work(system_power_efficient_wq,
1099+
&rt5682->jack_detect_work, msecs_to_jiffies(15));
1100+
return;
1101+
}
11001102

11011103
dapm = snd_soc_component_get_dapm(rt5682->component);
11021104

0 commit comments

Comments
 (0)