* [PATCH] ASoC: rt5665: do not block workqueue if card is unbound
@ 2026-11-17 4:13 Hyunjung Ko
2026-11-17 21:45 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Hyunjung Ko @ 2026-11-17 4:13 UTC (permalink / raw)
To: Mark Brown, Oder Chiou
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, linux-sound,
linux-kernel, stable, Hyunjung Ko
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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] ASoC: rt5665: do not block workqueue if card is unbound
2026-11-17 4:13 [PATCH] ASoC: rt5665: do not block workqueue if card is unbound Hyunjung Ko
@ 2026-11-17 21:45 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2026-11-17 21:45 UTC (permalink / raw)
To: Oder Chiou, Hyunjung Ko
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, linux-sound,
linux-kernel, stable
On Tue, 17 Nov 2026 13:13:23 +0900, Hyunjung Ko wrote:
> ASoC: rt5665: do not block workqueue if card is unbound
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.5
Thanks!
[1/1] ASoC: rt5665: do not block workqueue if card is unbound
https://git.kernel.org/broonie/sound/c/337a0fd20549
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-17 22:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 4:13 [PATCH] ASoC: rt5665: do not block workqueue if card is unbound Hyunjung Ko
2026-11-17 21:45 ` Mark Brown
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®