From: Hyunjung Ko <hj351016@gmail.com>
To: Mark Brown <broonie@kernel.org>, Oder Chiou <oder_chiou@realtek.com>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Hyunjung Ko <hj351016@gmail.com>
Subject: [PATCH] ASoC: rt5665: do not block workqueue if card is unbound
Date: Tue, 17 Nov 2026 13:13:23 +0900 [thread overview]
Message-ID: <20261117041323.4010546-1-hj351016@gmail.com> (raw)
Commit 4561d07d897f ("ASoC: rt5665: cancel jack detect work on removal
to avoid use-after-free") added cancel_delayed_work_sync() for
jack_detect_work and jd_check_work on shutdown and remove. However
rt5665_jack_detect_handler() and rt5665_calibrate_handler() busy-wait
inside the work callback until the component is bound, the card is
instantiated and calibration has finished. If such a work item is queued
and the device is then unbound before the card is instantiated, those
loops never make progress and cancel_delayed_work_sync() blocks forever.
calibrate_work is scheduled from rt5665_probe() but is never canceled, so
on unbind its handler can also run against the devm-freed rt5665_priv.
Reschedule the work with mod_delayed_work() when the card is not ready
yet instead of looping, and cancel calibrate_work on teardown too, as the
sibling rt5682 and rt5668 drivers already do:
commit 4c33de0673ce ("ASoC: rt5682: do not block workqueue if card is unbound")
commit a6d78661dc90 ("ASoC: rt5668: do not block workqueue if card is unbound")
Found by static analysis and code review; not runtime-reproduced (needs
RT5665 hardware).
Fixes: 4561d07d897f ("ASoC: rt5665: cancel jack detect work on removal to avoid use-after-free")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
sound/soc/codecs/rt5665.c | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/sound/soc/codecs/rt5665.c b/sound/soc/codecs/rt5665.c
index 4f7b13571369..27744497033a 100644
--- a/sound/soc/codecs/rt5665.c
+++ b/sound/soc/codecs/rt5665.c
@@ -1194,19 +1194,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 (!snd_soc_card_is_instantiated(rt5665->component->card)) {
- 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 ||
+ !snd_soc_card_is_instantiated(rt5665->component->card) ||
+ !rt5665->calibration_done) {
+ /* card not instantiated or calibration pending, try later */
+ mod_delayed_work(system_power_efficient_wq,
+ &rt5665->jack_detect_work, msecs_to_jiffies(15));
+ return;
}
guard(mutex)(&rt5665->calibrate_mutex);
@@ -4652,9 +4646,12 @@ static void rt5665_calibrate_handler(struct work_struct *work)
struct rt5665_priv *rt5665 = container_of(work, struct rt5665_priv,
calibrate_work.work);
- while (!snd_soc_card_is_instantiated(rt5665->component->card)) {
- pr_debug("%s\n", __func__);
- usleep_range(10000, 15000);
+ if (!rt5665->component ||
+ !snd_soc_card_is_instantiated(rt5665->component->card)) {
+ /* card not instantiated yet, try later */
+ mod_delayed_work(system_power_efficient_wq,
+ &rt5665->calibrate_work, msecs_to_jiffies(15));
+ return;
}
rt5665_calibrate(rt5665);
@@ -4840,6 +4837,7 @@ static void rt5665_i2c_shutdown(struct i2c_client *client)
disable_irq(client->irq);
cancel_delayed_work_sync(&rt5665->jack_detect_work);
cancel_delayed_work_sync(&rt5665->jd_check_work);
+ cancel_delayed_work_sync(&rt5665->calibrate_work);
regmap_write(rt5665->regmap, RT5665_RESET, 0);
}
--
2.43.0
reply other threads:[~2026-11-17 4:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117041323.4010546-1-hj351016@gmail.com \
--to=hj351016@gmail.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=oder_chiou@realtek.com \
--cc=perex@perex.cz \
--cc=stable@vger.kernel.org \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®