lkml.org 
[lkml]   [2022]   [Mar]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] ASoC: rt5665: Don't block workqueue if card is unbound
Date
The current rt5665_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: Zhen Ni <nizhen@uniontech.com>
---
sound/soc/codecs/rt5665.c | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/sound/soc/codecs/rt5665.c b/sound/soc/codecs/rt5665.c
index 33e889802ff8..cdfd7085df2a 100644
--- a/sound/soc/codecs/rt5665.c
+++ b/sound/soc/codecs/rt5665.c
@@ -1293,19 +1293,13 @@ static void rt5665_jack_detect_handler(struct work_struct *work)
container_of(work, struct rt5665_priv, jack_detect_work.work);
int val, btn_type;

- while (!rt5665->component) {
- pr_debug("%s codec = null\n", __func__);
- usleep_range(10000, 15000);
- }
-
- while (!rt5665->component->card->instantiated) {
- pr_debug("%s\n", __func__);
- usleep_range(10000, 15000);
- }
-
- while (!rt5665->calibration_done) {
- pr_debug("%s calibration not ready\n", __func__);
- usleep_range(10000, 15000);
+ if (!rt5665->component || !rt5665->component->card->instantiated ||
+ !rt5665->calibration_done) {
+ pr_debug("%s card not yet ready\n", __func__);
+ /* try later */
+ mod_delayed_work(system_power_efficient_wq,
+ &rt5665->jack_detect_work, msecs_to_jiffies(15));
+ return;
}

mutex_lock(&rt5665->calibrate_mutex);
--
2.20.1


\
 
 \ /
  Last update: 2022-03-04 07:28    [W:0.028 / U:2.244 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site