All of lore.kernel.org
 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 v1 7/7] ALSA: hda/cs35l41: rework how firmware requests are queued and flushed to prevent races
Date: Fri, 20 Nov 2026 16:41:01 +0000	[thread overview]
Message-ID: <sashiko-outbox-225582@kernel.org> (raw)
In-Reply-To: <20261120161136.157593-8-sbinding@opensource.cirrus.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ALSA: hda/cs35l41: DSP left running on cs35l41_hda_bind()
  error and unbind
- [Medium] ALSA: hda/cs35l41: missing DSP shutdown in cs35l41_hda_bind()
  and unbind
--

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

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

This commit queues CS35L41 firmware load work on system_freezable_wq, adds
a PM notifier to cancel or re-queue firmware loads across system suspend,
and moves ALSA control creation in cs35l41_hda_bind() outside fw_mutex.

> diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.c b/sound/hda/codecs/side-codecs/cs35l41_hda.c
> index 6f4b2088c5fe6..512b1a0094764 100644
> --- a/sound/hda/codecs/side-codecs/cs35l41_hda.c
> +++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c

[ ... ]

> @@ -1464,7 +1528,7 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
>  	struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
>  	struct hda_component_parent *parent = master_data;
>  	struct hda_component *comp;
> -	int ret = 0;
> +	int ret;
>  
>  	comp = hda_component_from_index(parent, cs35l41->index);
>  	if (!comp)
> @@ -1494,8 +1558,6 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
>  		dev_dbg(cs35l41->dev, "Firmware Autostart is disabled.\n");
>  	}
>  
> -	ret = cs35l41_create_controls(cs35l41);
> -
>  	comp->playback_hook = cs35l41_hda_playback_hook;
>  	comp->pre_playback_hook = cs35l41_hda_pre_playback_hook;
>  	comp->post_playback_hook = cs35l41_hda_post_playback_hook;
> @@ -1510,9 +1572,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,
> @@ -1520,6 +1591,15 @@ 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));
> +	scoped_guard(mutex, &cs35l41->fw_mutex) {
> +		cs35l41->request_fw_load = false;
> +	}
> +	cs35l41_fw_load_cancel_sync(cs35l41);
> +	cs35l41->codec = NULL;
> +
>  	return ret;
>  }

[Severity: Medium]
Does the err path leave the DSP running when cs35l41_create_controls()
fails?

Earlier in cs35l41_hda_bind(), cs35l41_smart_amp() loads and starts the
DSP synchronously rather than via fw_load_work.  Cancelling fw_load_work
and clearing request_fw_load without calling cs35l41_shutdown_dsp() leaves
cs_dsp.running and cs_dsp.booted set to true while unbound, so a later
bind calls cs_dsp_power_up() on an already running DSP and leaks
cs_dsp.alg_regions.

> @@ -1538,7 +1618,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 if cs_dsp.running is
true?

Resetting request_fw_load to false without calling cs35l41_shutdown_dsp()
leaves cs_dsp.running true across an unbind/rebind cycle, either causing
cs35l41_hda_bind() to run cs_dsp_power_up() on an active DSP when
firmware_autostart is enabled, or leaving request_fw_load out of sync with
cs_dsp.running so the next HDA_GEN_PCM_ACT_CLOSE unexpectedly unloads the
firmware.

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

      reply	other threads:[~2026-11-20 16:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 16:10 [PATCH v1 0/7] Fixes and improvements in CS35L41 HDA driver for System Suspend/Resume Stefan Binding
2026-11-20 16:10 ` [PATCH v1 1/7] ALSA: hda: cs35l41: Remove redundant lock_system_sleep() calls Stefan Binding
2026-11-20 16:10 ` [PATCH v1 2/7] ASoC: cs35l41: Prevent software reset when using SPI Stefan Binding
2026-11-20 16:22   ` sashiko-bot
2026-11-20 16:10 ` [PATCH v1 3/7] ALSA: hda: cs35l41: Unset irq if not used or configured Stefan Binding
2026-11-20 16:10 ` [PATCH v1 4/7] ALSA: hda/cs35l41: Split System Suspend/Resume callbacks Stefan Binding
2026-11-20 16:27   ` sashiko-bot
2026-11-20 16:10 ` [PATCH v1 5/7] ALSA: hda/cs35l41: Remove support for alternative firmware types Stefan Binding
2026-11-20 16:10 ` [PATCH v1 6/7] ALSA: hda/cs35l41: Store filenames of successfully loaded firmware and tunings Stefan Binding
2026-11-20 16:10 ` [PATCH v1 7/7] ALSA: hda/cs35l41: rework how firmware requests are queued and flushed to prevent races Stefan Binding
2026-11-20 16:41   ` 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-225582@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.