Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stefan Binding" <sbinding@opensource.cirrus.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH v2 7/7] ALSA: hda/cs35l41: rework how firmware requests are queued and flushed to prevent races
Date: Wed, 25 Nov 2026 12:18:50 +0000	[thread overview]
Message-ID: <sashiko-outbox-233349@kernel.org> (raw)
In-Reply-To: <20261125115124.9130-8-sbinding@opensource.cirrus.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ALSA: hda/cs35l41: DSP left running in cs35l41_hda_unbind()
--

commit a2a79af13f0805a482086a5ad2d46142a6d2a234
Author: Stefan Binding <sbinding@opensource.cirrus.com>

ALSA: hda/cs35l41: rework how firmware requests are queued and flushed to prevent races

This commit reworks firmware load scheduling in the CS35L41 HDA driver to
use system_freezable_wq, adds PM notifiers to cancel or re-queue firmware
work around system suspend, and moves control creation outside fw_mutex.

> diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.c b/sound/hda/codecs/side-codecs/cs35l41_hda.c
> index 51ac11270c88f..9a0063ff41590 100644
> --- a/sound/hda/codecs/side-codecs/cs35l41_hda.c
> +++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c

[ ... ]

> @@ -1521,9 +1583,18 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
>  
>  	mutex_unlock(&cs35l41->fw_mutex);
>  
> +	/* Create the necessary controls, do not create them under fw_mutex */
> +	ret = cs35l41_create_controls(cs35l41);
> +	if (ret) {
> +		dev_err(cs35l41->dev, "Failed to create controls: %d\n", ret);
> +		goto err;
> +	}
> +
>  	if (!device_link_add(&cs35l41->codec->core.dev, cs35l41->dev, DL_FLAG_STATELESS))
>  		dev_warn(dev, "Unable to create device link\n");
>  
> +	register_pm_notifier(&cs35l41->pm_notifier);
> +
>  	dev_info(cs35l41->dev,
>  		 "CS35L41 Bound - SSID: %s, BST: %d, VSPK: %d, CH: %c, FW EN: %d, SPKID: %d\n",
>  		 cs35l41->acpi_subsystem_id, cs35l41->hw_cfg.bst_type,
> @@ -1531,6 +1602,17 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
>  		 channel_name[cs35l41->hw_cfg.spk_pos],
>  		 cs35l41->cs_dsp.running, cs35l41->speaker_id);
>  
> +	return 0;
> +err:
> +	memset(comp, 0, sizeof(*comp));
> +	cs35l41_fw_load_cancel_sync(cs35l41);
> +	scoped_guard(mutex, &cs35l41->fw_mutex) {
> +		cs35l41->request_fw_load = false;
> +		if (cs35l41->halo_initialized)
> +			cs35l41_shutdown_dsp(cs35l41);
> +	}
> +	cs35l41->codec = NULL;
> +
>  	return ret;
>  }
>  
> @@ -1549,7 +1631,11 @@ static void cs35l41_hda_unbind(struct device *dev, struct device *master, void *
>  		memset(comp, 0, sizeof(*comp));
>  
>  		cs35l41_remove_controls(cs35l41);
> -		cancel_work_sync(&cs35l41->fw_load_work);
> +		scoped_guard(mutex, &cs35l41->fw_mutex) {
> +			cs35l41->request_fw_load = false;
> +		}
> +		unregister_pm_notifier(&cs35l41->pm_notifier);
> +		cs35l41_fw_load_cancel_sync(cs35l41);
>  		cs35l41->codec = NULL;
>  	}
>  }

[Severity: Medium]
Should cs35l41_hda_unbind() also shut down the DSP (with the device
runtime-resumed) after cancelling fw_load_work, just like the err path in
cs35l41_hda_bind()?

Clearing cs35l41->request_fw_load without calling cs35l41_shutdown_dsp()
leaves cs35l41->cs_dsp.running set to true.  If the component is unbound
and later rebound without removing the CS35L41 device, cs35l41_hda_bind()
calls cs_dsp_power_up() on an already-running DSP when firmware_autostart
is enabled (leaking duplicate cs_dsp.alg_regions entries), or leaves
cs_dsp.running and request_fw_load out of sync so the next
HDA_GEN_PCM_ACT_CLOSE queues fw_load_work to unload the running firmware.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125115124.9130-1-sbinding@opensource.cirrus.com?part=7

      reply	other threads:[~2026-11-25 12:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 11:50 [PATCH v2 0/7] Fixes and improvements in CS35L41 HDA driver for System Suspend/Resume Stefan Binding
2026-11-25 11:50 ` [PATCH v2 1/7] ALSA: hda: cs35l41: Remove redundant lock_system_sleep() calls Stefan Binding
2026-11-25 11:50 ` [PATCH v2 2/7] ASoC: cs35l41: Prevent software reset when using SPI Stefan Binding
2026-11-25 11:50 ` [PATCH v2 3/7] ALSA: hda: cs35l41: Unset irq if not used or configured Stefan Binding
2026-11-25 11:50 ` [PATCH v2 4/7] ALSA: hda/cs35l41: Split System Suspend/Resume callbacks Stefan Binding
2026-11-25 11:50 ` [PATCH v2 5/7] ALSA: hda/cs35l41: Remove support for alternative firmware types Stefan Binding
2026-11-25 11:50 ` [PATCH v2 6/7] ALSA: hda/cs35l41: Store filenames of successfully loaded firmware and tunings Stefan Binding
2026-11-25 11:50 ` [PATCH v2 7/7] ALSA: hda/cs35l41: rework how firmware requests are queued and flushed to prevent races Stefan Binding
2026-11-25 12:18   ` 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-233349@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sbinding@opensource.cirrus.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