From: sashiko-bot@kernel.org
To: "Marc Herrero" <marcht@proton.me>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH v2] ASoC: qcom: audioreach: apply volume changes to a running graph
Date: Mon, 16 Nov 2026 20:41:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-217669@kernel.org> (raw)
In-Reply-To: <20261116-q6apm-vol-live-v2-1-fbeba4402984@proton.me>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ASoC: qcom: audioreach: race in
audioreach_put_vol_ctrl_audio_mixer()
--
commit ddae8fd71fb67b8ccdf92f805eed45f2ce14176d
Author: Marc Herrero <marcht@proton.me>
ASoC: qcom: audioreach: apply volume changes to a running graph
This commit sends volume updates from audioreach_put_vol_ctrl_audio_mixer()
directly to the DSP when the widget is powered and its graph is started,
holding the DAPM mutex across the check and update.
> diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c
> index 8e3314a2738c0..034d42edde22c 100644
> --- a/sound/soc/qcom/qdsp6/q6apm.c
> +++ b/sound/soc/qcom/qdsp6/q6apm.c
> @@ -839,6 +839,19 @@ int q6apm_graph_stop(struct q6apm_graph *graph)
> }
> EXPORT_SYMBOL_GPL(q6apm_graph_stop);
>
> +bool q6apm_is_graph_started(struct q6apm *apm, uint32_t graph_id)
> +{
> + struct audioreach_graph *graph;
> + bool started;
> +
> + mutex_lock(&apm->lock);
> + graph = idr_find(&apm->graph_idr, graph_id);
> + started = graph && graph->start_count > 0;
> + mutex_unlock(&apm->lock);
> +
> + return started;
> +}
[ ... ]
> diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
> index 612d8f03e6e98..956f8e9e6a762 100644
> --- a/sound/soc/qcom/qdsp6/topology.c
> +++ b/sound/soc/qcom/qdsp6/topology.c
> @@ -1322,11 +1322,33 @@ static int audioreach_put_vol_ctrl_audio_mixer(struct snd_kcontrol *kcontrol,
> struct snd_ctl_elem_value *ucontrol)
> {
> struct snd_soc_dapm_widget *dw = snd_soc_dapm_kcontrol_to_widget(kcontrol);
> + struct snd_soc_component *c = snd_soc_dapm_to_component(dw->dapm);
> struct audioreach_module *mod = dw->dobj.private;
> + struct q6apm *apm = dev_get_drvdata(c->dev);
> + long gain = ucontrol->value.integer.value[0];
> + int ret = 0;
>
> - mod->gain = ucontrol->value.integer.value[0];
> + /*
> + * The PGA event applies the gain when the widget powers up. Hold the
> + * DAPM lock so the power state cannot change under us: either the
> + * event sees the new gain or it is sent here. The DSP only accepts
> + * the parameter once the graph holding the module has been started.
> + * Keep the old gain if the DSP did not take the new one, so that
> + * writing the same value again retries.
> + */
> + snd_soc_dapm_mutex_lock(dw->dapm);
> + if (mod->gain != gain) {
> + if (dw->power &&
> + q6apm_is_graph_started(apm, mod->container->sub_graph->info->id))
> + ret = audioreach_gain_set_vol_ctrl(apm, mod, gain);
> + if (!ret) {
> + mod->gain = gain;
> + ret = 1;
> + }
> + }
> + snd_soc_dapm_mutex_unlock(dw->dapm);
>
> - return 1;
> + return ret;
> }
[Severity: Medium]
Can audioreach_put_vol_ctrl_audio_mixer() still race with
q6apm_dai_prepare() or q6apm_dai_close() because graph start and stop
do not hold the DAPM lock or synchronize start_count under apm->lock?
CPU0 CPU1
q6apm_dai_prepare()
q6apm_graph_stop()
--ar_graph->start_count; (0)
audioreach_put_vol_ctrl_audio_mixer()
snd_soc_dapm_mutex_lock(dw->dapm)
dw->power is 1
q6apm_is_graph_started() -> false
mod->gain = gain;
snd_soc_dapm_mutex_unlock(dw->dapm)
...
q6apm_graph_start()
ar_graph->start_count++; (1)
...
snd_soc_dapm_stream_event(START)
/* dw->power already 1:
POST_PMU does not run */ <-- DSP keeps old gain
When an active stream is re-prepared (for example after XRUN or stop),
q6apm_dai_prepare() stops the graph while dw->power stays 1 across several
DSP IPCs before restarting it. A volume change in that window sees
q6apm_is_graph_started() return false and only updates mod->gain; because
dw->power is already 1, SND_SOC_DAPM_POST_PMU never fires again, leaving
the running graph at the old volume while mod->gain == gain blocks retries
of the same value.
Conversely, during shutdown, dpcm_fe_dai_shutdown() runs q6apm_dai_close()
-> q6apm_graph_stop() and q6apm_graph_close() before
dpcm_dapm_stream_event(SND_SOC_DAPM_STREAM_STOP) takes the DAPM lock and
clears dw->power. If q6apm_is_graph_started() returns true just before the
graph stops and closes, audioreach_gain_set_vol_ctrl() fails on the DSP
(-EINVAL) and discards the new gain.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-q6apm-vol-live-v2-1-fbeba4402984@proton.me?part=1
prev parent reply other threads:[~2026-11-16 20:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 20:16 [PATCH v2] ASoC: qcom: audioreach: apply volume changes to a running graph Marc Herrero via B4 Relay
2026-11-16 20:16 ` Marc Herrero
2026-11-16 20: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-217669@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=marcht@proton.me \
--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 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.