* [PATCH] ALSA: hda: Reset jack_detect on failure
@ 2026-12-04 7:49 Sreeraj S Kurup
2026-12-04 8:13 ` sashiko-bot
2026-12-04 9:03 ` [PATCH v2] " Sreeraj S Kurup
0 siblings, 2 replies; 4+ messages in thread
From: Sreeraj S Kurup @ 2026-12-04 7:49 UTC (permalink / raw)
To: perex, tiwai; +Cc: linux-sound, linux-kernel, Sreeraj S Kurup
Reset jack_detect to 0 when enabling jack
detection fails.
This allows a later call to try enabling
jack detection again.
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
sound/hda/common/jack.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/sound/hda/common/jack.c b/sound/hda/common/jack.c
index 6b8aa1a6c008..9fda0bdd97e9 100644
--- a/sound/hda/common/jack.c
+++ b/sound/hda/common/jack.c
@@ -364,8 +364,10 @@ snd_hda_jack_detect_enable_callback_mst(struct hda_codec *codec, hda_nid_t nid,
err = snd_hda_codec_write_cache(codec, nid, 0,
AC_VERB_SET_UNSOLICITED_ENABLE,
AC_USRSP_EN | jack->tag);
- if (err < 0)
+ if (err < 0) {
+ jack->jack_detect = 0;
return ERR_PTR(err);
+ }
return callback;
}
EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable_callback_mst);
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ALSA: hda: Reset jack_detect on failure
2026-12-04 7:49 [PATCH] ALSA: hda: Reset jack_detect on failure Sreeraj S Kurup
@ 2026-12-04 8:13 ` sashiko-bot
2026-12-04 9:03 ` [PATCH v2] " Sreeraj S Kurup
1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-04 8:13 UTC (permalink / raw)
To: Sreeraj S Kurup; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ALSA: hda: unlocked hda_jack_tbl bitfield race on jack_detect
reset
- [Low] ALSA: hda: missing Fixes trailer for jack_detect error reset
--
commit 0d601e39d22a878d7df0b6f309b26383e1690de7
Author: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
> ALSA: hda: Reset jack_detect on failure
>
> Reset jack_detect to 0 when enabling jack
> detection fails.
>
> This allows a later call to try enabling
> jack detection again.
>
> Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
[Severity: Low]
This looks like a bug fix for leaving jack_detect set after a failed verb
write. Should this include:
Fixes: 01a61e12b460 ("ALSA: hda - Create jack-detection kcontrols")
> diff --git a/sound/hda/common/jack.c b/sound/hda/common/jack.c
> index 6b8aa1a6c0084..9fda0bdd97e93 100644
> --- a/sound/hda/common/jack.c
> +++ b/sound/hda/common/jack.c
> @@ -364,8 +364,10 @@ snd_hda_jack_detect_enable_callback_mst(struct hda_codec *codec, hda_nid_t nid,
> err = snd_hda_codec_write_cache(codec, nid, 0,
> AC_VERB_SET_UNSOLICITED_ENABLE,
> AC_USRSP_EN | jack->tag);
> - if (err < 0)
> + if (err < 0) {
> + jack->jack_detect = 0;
> return ERR_PTR(err);
> + }
> return callback;
> }
> EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable_callback_mst);
[Severity: Medium]
Can resetting jack->jack_detect here introduce a data race with concurrent
jack->jack_dirty updates?
In struct hda_jack_tbl, jack_detect and jack_dirty share the same unsigned
int bitfield word with no lock protecting it. Before this patch,
jack->jack_detect was set once during probe before codec registration and
never cleared.
Resetting it on failure allows later runtime resumes on codecs that ignore
the return value (such as simplehdmi or DP-MST generic HDMI) to re-enter
snd_hda_jack_detect_enable_callback_mst() while bus->unsol_work is active,
since hda_codec_unsol_event() only filters events during system sleep.
CPU0 (runtime resume) CPU1 (bus->unsol_work)
hda_call_codec_resume()
snd_hda_hdmi_simple_init()
...
hda_codec_unsol_event()
snd_hda_hdmi_simple_unsol_event()
snd_hda_jack_set_dirty_all()
jack->jack_detect = 0; jack->jack_dirty = 1; <-- data race
An interleaved read-modify-write can lose a jack->jack_dirty update,
causing jack_detect_update() to skip reading pin sense and drop a hotplug
event, or clobber jack->jack_detect. Separating jack_detect from the
bitfield word or locking struct hda_jack_tbl flag updates would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204074922.2913-1-sreekuttan2156239@gmail.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] ALSA: hda: Reset jack_detect on failure
2026-12-04 7:49 [PATCH] ALSA: hda: Reset jack_detect on failure Sreeraj S Kurup
2026-12-04 8:13 ` sashiko-bot
@ 2026-12-04 9:03 ` Sreeraj S Kurup
2026-12-04 9:31 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Sreeraj S Kurup @ 2026-12-04 9:03 UTC (permalink / raw)
To: sreekuttan2156239, perex, tiwai; +Cc: linux-kernel, linux-sound
Reset jack_detect to 0 when enabling jack
detection fails.
This allows a later call to try enabling
jack detection again.
Fixes: 01a61e12b460 ("ALSA: hda - Create jack-detection kcontrols")
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
v2:
- Add Fixes Trailer.
sound/hda/common/jack.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/sound/hda/common/jack.c b/sound/hda/common/jack.c
index 6b8aa1a6c008..9fda0bdd97e9 100644
--- a/sound/hda/common/jack.c
+++ b/sound/hda/common/jack.c
@@ -364,8 +364,10 @@ snd_hda_jack_detect_enable_callback_mst(struct hda_codec *codec, hda_nid_t nid,
err = snd_hda_codec_write_cache(codec, nid, 0,
AC_VERB_SET_UNSOLICITED_ENABLE,
AC_USRSP_EN | jack->tag);
- if (err < 0)
+ if (err < 0) {
+ jack->jack_detect = 0;
return ERR_PTR(err);
+ }
return callback;
}
EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable_callback_mst);
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ALSA: hda: Reset jack_detect on failure
2026-12-04 9:03 ` [PATCH v2] " Sreeraj S Kurup
@ 2026-12-04 9:31 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-04 9:31 UTC (permalink / raw)
To: Sreeraj S Kurup; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ALSA: hda: unlocked hda_jack_tbl bitfield race on jack_detect
reset
- [Medium] ALSA: hda: race from setting jack_detect before verb write
completes
--
commit e13216d6c208b5b57631ab503cd320a4c0cfba0f
Author: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
ALSA: hda: Reset jack_detect on failure
This commit resets jack->jack_detect to 0 in
snd_hda_jack_detect_enable_callback_mst() when snd_hda_codec_write_cache()
fails, allowing subsequent calls to retry enabling unsolicited responses.
> diff --git a/sound/hda/common/jack.c b/sound/hda/common/jack.c
> index 6b8aa1a6c0084..9fda0bdd97e93 100644
> --- a/sound/hda/common/jack.c
> +++ b/sound/hda/common/jack.c
> @@ -364,8 +364,10 @@ snd_hda_jack_detect_enable_callback_mst(struct hda_codec *codec, hda_nid_t nid,
> err = snd_hda_codec_write_cache(codec, nid, 0,
> AC_VERB_SET_UNSOLICITED_ENABLE,
> AC_USRSP_EN | jack->tag);
> - if (err < 0)
> + if (err < 0) {
> + jack->jack_detect = 0;
> return ERR_PTR(err);
> + }
[Severity: Medium]
Can resetting jack->jack_detect on failure introduce a data race with
jack->jack_dirty updates?
In struct hda_jack_tbl, jack_detect and jack_dirty are 1-bit fields in
the same unsigned int with no lock protecting them. Previously,
jack->jack_detect was set once at probe and never cleared, so later
calls returned early without writing the bitfield.
With this change, a codec whose init callback ignores errors (such as
snd_hda_hdmi_simple_init()) retries enabling jack detection on runtime
resume, where unsolicited event work can still run because
dev.power.power_state.event stays PM_EVENT_ON:
CPU0 (runtime resume) CPU1 (bus->unsol_work)
hda_codec_runtime_resume() snd_hdac_bus_process_unsol_events()
hda_call_codec_resume() hda_codec_unsol_event()
snd_hda_hdmi_simple_init() snd_hda_hdmi_simple_unsol_event()
... snd_hda_jack_set_dirty_all()
jack->jack_detect = 1; jack->jack_dirty = 1;
<-- bitfield data race
jack->jack_detect = 0;
Concurrent non-atomic read-modify-write operations on the shared word
can lose a jack_dirty = 1 update (dropping a hotplug event) or
overwrite jack_detect.
[Severity: Medium]
Should jack->jack_detect only be set after snd_hda_codec_write_cache()
succeeds, rather than setting it beforehand and rolling it back?
During a bus reset, snd_hda_bus_reset_codecs() calls
hda_call_codec_resume() whenever hda_codec_is_power_on() is true,
including during RPM_RESUMING. After a probe-time failure on a
simplehdmi codec, this can race with runtime resume:
CPU0 (runtime resume) CPU1 (bus reset)
snd_hda_hdmi_simple_init() snd_hda_bus_reset_codecs()
... hda_call_codec_resume()
jack->jack_detect = 1; snd_hda_hdmi_simple_init()
...
if (jack->jack_detect)
return callback; <-- skipped
snd_hda_codec_write_cache() fails
jack->jack_detect = 0;
CPU1 skips enabling unsolicited responses because it sees the transient
jack_detect == 1, and its regmap sync does not write
AC_VERB_SET_UNSOLICITED_ENABLE because it is not cached yet. Jack
detection then stays disabled until a later resume retries.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204090300.3099-1-sreekuttan2156239@gmail.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-04 9:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 7:49 [PATCH] ALSA: hda: Reset jack_detect on failure Sreeraj S Kurup
2026-12-04 8:13 ` sashiko-bot
2026-12-04 9:03 ` [PATCH v2] " Sreeraj S Kurup
2026-12-04 9:31 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox