[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20220304062758.9701-1-nizhen@uniontech.com>
Date: Fri, 4 Mar 2022 14:27:58 +0800
From: Zhen Ni <nizhen@...ontech.com>
To: oder_chiou@...ltek.com, broonie@...nel.org, tiwai@...e.com
Cc: alsa-devel@...a-project.org, linux-kernel@...r.kernel.org,
Zhen Ni <nizhen@...ontech.com>
Subject: [PATCH] ASoC: rt5665: Don't block workqueue if card is unbound
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@...ontech.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
Powered by blists - more mailing lists