From: sashiko-bot@kernel.org
To: "Yaohan Li" <shunsheng1218@gmail.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH] ASoC: rt5645: stop jack detection on component remove
Date: Thu, 03 Dec 2026 09:23:43 +0000 [thread overview]
Message-ID: <sashiko-outbox-247453@kernel.org> (raw)
In-Reply-To: <20261203085309.2392653-1-shunsheng1218@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] ASoC: rt5645: data race on en_button_func in
rt5645_set_bias_level()
--
commit 99a615fa9435b7376ff9a3e1e4c3496127c1c760
Author: Yaohan Li <shunsheng1218@gmail.com>
ASoC: rt5645: stop jack detection on component remove
This patch serializes access to rt5645->component and the jack pointers
under jd_mutex, clears them and stops btn_check_timer and jack_detect_work
in rt5645_remove(), and moves snd_soc_jack_report() outside jd_mutex. It
also queues and flushes jack_detect_work in rt5645_sys_resume() instead of
calling the work handler directly.
> diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
> index e14b66d3118da..92a54e66f14c3 100644
> --- a/sound/soc/codecs/rt5645.c
> +++ b/sound/soc/codecs/rt5645.c
> @@ -3278,19 +3278,28 @@ int rt5645_set_jack_detect(struct snd_soc_component *component,
> {
> struct rt5645_priv *rt5645 = snd_soc_component_get_drvdata(component);
>
> - rt5645->hp_jack = hp_jack;
> - rt5645->mic_jack = mic_jack;
> - rt5645->btn_jack = btn_jack;
> - if (rt5645->btn_jack && rt5645->codec_type == CODEC_TYPE_RT5650) {
> - rt5645->en_button_func = true;
> - regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
> - RT5645_GP1_PIN_IRQ, RT5645_GP1_PIN_IRQ);
> - regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL1,
> - RT5645_DIG_GATE_CTRL, RT5645_DIG_GATE_CTRL);
> - regmap_update_bits(rt5645->regmap, RT5645_DEPOP_M1,
> - RT5645_HP_CB_MASK, RT5645_HP_CB_PU);
> + scoped_guard(mutex, &rt5645->jd_mutex) {
> + if (!rt5645->component)
> + return -ENODEV;
> +
> + rt5645->hp_jack = hp_jack;
> + rt5645->mic_jack = mic_jack;
> + rt5645->btn_jack = btn_jack;
> + if (rt5645->btn_jack && rt5645->codec_type == CODEC_TYPE_RT5650) {
> + rt5645->en_button_func = true;
> + regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
> + RT5645_GP1_PIN_IRQ, RT5645_GP1_PIN_IRQ);
> + regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL1,
> + RT5645_DIG_GATE_CTRL, RT5645_DIG_GATE_CTRL);
> + regmap_update_bits(rt5645->regmap, RT5645_DEPOP_M1,
> + RT5645_HP_CB_MASK, RT5645_HP_CB_PU);
> + } else {
> + rt5645->en_button_func = false;
> + }
[Severity: Low]
Can this write to rt5645->en_button_func race with rt5645_set_bias_level()?
During card teardown, soc_cleanup_card_resources() calls snd_soc_link_exit()
before snd_soc_flush_all_delayed_work(). On RT5650 boards whose machine
driver clears the jack in dai_link->exit() (such as mt8189-nau8825) and
leaves playback pmdown_time enabled, snd_soc_close_delayed_work() can run
concurrently under card->dapm_mutex:
CPU0 CPU1
soc_cleanup_card_resources()
snd_soc_dapm_shutdown()
snd_soc_link_exit() snd_soc_close_delayed_work()
mt8189_headset_codec_exit() snd_soc_dapm_stream_event()
rt5645_set_jack_detect() dapm_power_widgets()
lock(&rt5645->jd_mutex) rt5645_set_bias_level()
rt5645->en_button_func = false if (rt5645->en_button_func)
<-- data race
If rt5645_jack_detect_work() dirties forced supply pins between
snd_soc_dapm_shutdown() and snd_soc_link_exit(), dapm_power_widgets()
transitions the codec back to SND_SOC_BIAS_STANDBY and reads
rt5645->en_button_func without holding jd_mutex.
This is a KCSAN data race, though reading a stale true value only queues
jack_detect_work redundantly before rt5645_remove() cancels it. Since
rt5645_set_bias_level() runs under card->dapm_mutex and cannot take jd_mutex
without inverting lock order with rt5645_jack_detect_work(), using
READ_ONCE() and WRITE_ONCE() on rt5645->en_button_func would avoid the race.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203085309.2392653-1-shunsheng1218@gmail.com?part=1
prev parent reply other threads:[~2026-12-03 9:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 8:53 [PATCH] ASoC: rt5645: stop jack detection on component remove Yaohan Li
2026-12-03 9:23 ` sashiko-bot [this message]
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=sashiko-outbox-247453@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shunsheng1218@gmail.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