Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shih-Yuan Lee" <fourdollars@debian.org>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH v1 1/2] ALSA: hda/cs420x: Add CS4208 TDM speaker fixup for MacBook8,1
Date: Tue, 01 Dec 2026 16:04:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-243637@kernel.org> (raw)
In-Reply-To: <20261201153214.25157-2-fourdollars@debian.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ALSA: hda/cs420x: lock inversion between gpio_mutex and
  runtime PM
--

commit fa5307267e50e6ff89619572855f03b4f32adc6e
Author: Shih-Yuan Lee <fourdollars@debian.org>

ALSA: hda/cs420x: Add CS4208 TDM speaker fixup for MacBook8,1

This commit adds a CS4208 fixup for the 12-inch MacBook (MacBook8,1) to
configure its 4-channel TDM digital speaker link, pin defaults, vendor
coefficients, and GPIO0 speaker amplifier control.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=110561

> diff --git a/sound/hda/codecs/cirrus/cs420x.c b/sound/hda/codecs/cirrus/cs420x.c
> index 6cba01228c271..d389fd8961d60 100644
> --- a/sound/hda/codecs/cirrus/cs420x.c
> +++ b/sound/hda/codecs/cirrus/cs420x.c
[ ... ]
> @@ -118,12 +126,55 @@ static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx,
>   * HP/SPK/SPDIF
>   */
>  
> +static hda_nid_t cs4208_mb81_hp_pin(struct hda_codec *codec)
> +{
> +	struct cs_spec *spec = codec->spec;
> +	const struct auto_pin_cfg *cfg = &spec->gen.autocfg;
> +
> +	if (cfg->hp_outs)
> +		return cfg->hp_pins[0];
> +	if (cfg->line_outs && cfg->line_out_type == AUTO_PIN_HP_OUT)
> +		return cfg->line_out_pins[0];
> +	return 0;
> +}
> +
> +static bool cs4208_mb81_hp_present(struct hda_codec *codec)
> +{
> +	hda_nid_t hp_pin = cs4208_mb81_hp_pin(codec);
> +
> +	return hp_pin && snd_hda_jack_detect(codec, hp_pin);
> +}
> +
> +static void cs4208_mb81_update_gpio(struct hda_codec *codec, bool write_mask)
> +{
> +	struct cs_spec *spec = codec->spec;
> +	struct cs4208_mb81_data *mb81 = spec->mb81;
> +	bool hp_present;
> +
> +	mutex_lock(&mb81->gpio_mutex);
> +	hp_present = cs4208_mb81_hp_present(codec);
> +	spec->gpio_data = hp_present ?
> +		spec->gpio_eapd_hp : spec->gpio_eapd_speaker;
> +	if (write_mask)
> +		snd_hda_codec_set_gpio(codec, spec->gpio_mask, spec->gpio_dir,
> +				       spec->gpio_data, 0);
> +	else
> +		snd_hda_codec_write(codec, 0x01, 0,
> +				    AC_VERB_SET_GPIO_DATA, spec->gpio_data);
> +	mutex_unlock(&mb81->gpio_mutex);
> +}

[Severity: Medium]
Can cs4208_mb81_update_gpio() deadlock between mb81->gpio_mutex and codec
runtime PM?

During runtime resume, hda_codec_runtime_resume() calls cs_init() ->
cs4208_mb81_update_gpio(codec, true), acquiring mb81->gpio_mutex inside
the runtime resume callback.  However, cs4208_mb81_update_gpio() also
issues HDA verbs while holding mb81->gpio_mutex, and each verb in
call_exec_verb() calls snd_hda_power_up_pm(codec) ->
pm_runtime_get_sync():

cs_automute()
  cs4208_mb81_update_gpio(codec, false)
    mutex_lock(&mb81->gpio_mutex)
    snd_hda_codec_write()
      ...
        call_exec_verb()
          snd_hda_power_up_pm()
            pm_runtime_get_sync()
              hda_codec_runtime_resume()
                ...
                  cs_init()
                    cs4208_mb81_update_gpio(codec, true)
                      mutex_lock(&mb81->gpio_mutex)  <-- deadlocks

When cs_automute() runs without the caller pinning runtime PM (such as
from snd_hda_jack_unsol_event(), or from mixer control callbacks like
automute_mode_put() even after commit "ALSA: hda/cs420x: Support headset
mic type detection on MacBook8,1" wraps unsol_event in
snd_hda_power_up()), snd_hda_gen_update_outputs() releases any temporary
per-verb runtime PM reference before returning.  If the codec is runtime
suspended or concurrently resuming when cs4208_mb81_update_gpio() enters
snd_hda_codec_write(), pm_runtime_get_sync() will run or wait for
hda_codec_runtime_resume() and deadlock on mb81->gpio_mutex.

Calling snd_hda_power_up_pm(codec) before mutex_lock(&mb81->gpio_mutex)
and snd_hda_power_down_pm(codec) after mutex_unlock(&mb81->gpio_mutex)
would keep the lock ordering consistent across all paths.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201153214.25157-1-fourdollars@debian.org?part=1

  reply	other threads:[~2026-12-01 16:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 15:32 [PATCH v1 0/2] ALSA: hda/cs420x: MacBook8,1 speakers and headset mic Shih-Yuan Lee
2026-12-01 15:32 ` [PATCH v1 1/2] ALSA: hda/cs420x: Add CS4208 TDM speaker fixup for MacBook8,1 Shih-Yuan Lee
2026-12-01 16:04   ` sashiko-bot [this message]
2026-12-01 15:32 ` [PATCH v1 2/2] ALSA: hda/cs420x: Support headset mic type detection on MacBook8,1 Shih-Yuan Lee

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-243637@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fourdollars@debian.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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