From: sashiko-bot@kernel.org
To: "Srinivas Kandagatla" <srinivas.kandagatla@oss.qualcomm.com>
Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v5 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag
Date: Fri, 04 Dec 2026 12:01:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-249742@kernel.org> (raw)
In-Reply-To: <20261204113101.1141644-3-srinivas.kandagatla@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [Medium] ASoC: soc-dapm: dapm_codec_stream_event() affects unflipped
codec DAIs
- [Medium] ASoC: soc-pcm: opposite-direction codec DAIs still receive
mute_stream()
- [Medium] ASoC: soc-pcm: soc_pcm_dapm_update_dai_at_stream() always
writes stream
- [Medium] ASoC: soc-pcm: duplicate dapm_power_widgets() pass and
unneeded export
- [Medium] ASoC: soc-pcm: soc_pcm_hw_clean() ignores pmdown_time for
flipped codecs
- [Medium] ASoC: soc-pcm: flipped codec DAIs contaminate symmetry
constraints
- [Medium] ASoC: soc-pcm: substream->stream flip races with
dpcm_be_dai_trigger()
--
commit fcaf0cac3ec4ae2256dfd816dfc3e318cc74138a
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
ASoC: soc-pcm: add multi_direction_codecs link flag
This commit adds a multi_direction_codecs flag and an optional
multi_direction_params_fixup callback to struct snd_soc_dai_link so
opposite-direction codec DAIs on a link have .hw_params, .hw_free, and DAPM
stream events run in their own direction.
> diff --git a/Documentation/sound/soc/multi-direction-codecs.rst b/Documentation/sound/soc/multi-direction-codecs.rst
> new file mode 100644
> index 0000000000000..8d3fa62bb1c6a
> --- /dev/null
> +++ b/Documentation/sound/soc/multi-direction-codecs.rst
[ ... ]
> +Only ``.hw_params`` and ``.hw_free`` are called on the opposite-direction
> +codec DAIs. Their ``.startup``, ``.prepare``, ``.trigger``,
> +``.shutdown`` and mute callbacks are not, so a codec DAI used this way
> +must not depend on them.
[Severity: Medium]
Are mute callbacks actually skipped for opposite-direction codec DAIs?
snd_soc_dai_digital_mute() does not check snd_soc_dai_stream_valid(), and
snd_soc_runtime_action() increments stream[stream].active on every DAI on
the link. __soc_pcm_prepare(), soc_pcm_hw_clean(),
snd_soc_pcm_dai_trigger(), and snd_soc_playback_digital_mute() iterate
for_each_rtd_dais(), so an opposite-direction codec DAI that defines
.mute_stream will still be called with the unflipped stream direction.
Also, the machine-driver example below describes a DPCM backend link but
omits .no_pcm = 1, which would instead register a userspace-exposed PCM.
[ ... ]
> diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
> index 3ef13d2b1f5e9..4bda3e5b930d0 100644
> --- a/sound/soc/soc-dapm.c
> +++ b/sound/soc/soc-dapm.c
> @@ -4670,6 +4670,18 @@ static void dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, int e
> dapm_power_widgets(rtd->card, event, NULL);
> }
>
> +static void dapm_codec_stream_event(struct snd_soc_pcm_runtime *rtd,
> + int stream, int event)
> +{
> + struct snd_soc_dai *codec_dai;
> + int i;
> +
> + for_each_rtd_codec_dais(rtd, i, codec_dai)
> + dapm_dai_stream_event(codec_dai, stream, event);
> +
> + dapm_power_widgets(rtd->card, event, NULL);
> +}
[Severity: Medium]
Can dapm_codec_stream_event() toggle widgets on bidirectional codec DAIs
that were never direction-flipped?
__soc_pcm_hw_params() and soc_pcm_hw_clean() only flip a codec DAI when
!snd_soc_dai_stream_valid(codec_dai, substream->stream), so a codec DAI
supporting both directions stays unflipped. Because
dapm_codec_stream_event() iterates every codec DAI without that check and
dapm_dai_stream_event() uses non-refcounted w->active and w->is_ep flags,
__soc_pcm_prepare() will power up an unconfigured opposite-direction path
and soc_pcm_hw_clean() will power down an active stream in that direction.
Link instantiation also does not validate that a multi_direction_codecs
link is unidirectional, so setting the flag on a bidirectional link lets
one direction clobber the other's DAI and DAPM state.
[ ... ]
> @@ -4691,6 +4703,26 @@ void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
> snd_soc_dapm_mutex_unlock(card);
> }
>
> +/**
> + * snd_soc_dapm_codec_stream_event - stream event limited to codec-side DAIs
> + * @rtd: PCM runtime data
> + * @stream: stream direction
> + * @event: stream event
> + *
> + * Variant of snd_soc_dapm_stream_event() that only targets codec-side DAIs.
> + * Used by multi_direction_codecs links to power up/down the flipped-
> + * direction codec widgets without altering the CPU DAI's direction
> + * tracking.
> + */
> +void snd_soc_dapm_codec_stream_event(struct snd_soc_pcm_runtime *rtd,
> + int stream, int event)
> +{
> + snd_soc_dapm_mutex_lock(rtd->card);
> + dapm_codec_stream_event(rtd, stream, event);
> + snd_soc_dapm_mutex_unlock(rtd->card);
> +}
> +EXPORT_SYMBOL_GPL(snd_soc_dapm_codec_stream_event);
[Severity: Medium]
Why is this a separate exported entry point instead of handling
multi_direction_codecs inside dapm_stream_event()?
Calling snd_soc_dapm_codec_stream_event() right after
snd_soc_dapm_stream_event() or snd_soc_dapm_stream_stop() takes
card->dapm_mutex twice and runs two full-card dapm_power_widgets() passes
(including duplicate bias-domain syncs, component stream_event callbacks,
and pop waits) on every prepare and hw_free, while also allowing other
DAPM work to interleave between powering up the two directions.
EXPORT_SYMBOL_GPL() is also unnecessary here since
snd_soc_dapm_stream_event() is unexported and soc-dapm.o and soc-pcm.o are
in the same snd-soc-core module.
[ ... ]
> diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
> index dac353fec4bcf..c1b32c5f2f2dc 100644
> --- a/sound/soc/soc-pcm.c
> +++ b/sound/soc/soc-pcm.c
[ ... ]
> +/* hw_free counterpart to soc_pcm_dai_hw_params_at_stream(). */
> +static void soc_pcm_dai_hw_free_at_stream(struct snd_soc_dai *dai,
> + struct snd_pcm_substream *substream,
> + int rollback, int stream)
> +{
> + int saved_stream = substream->stream;
> +
> + if (stream == saved_stream) {
> + snd_soc_dai_hw_free(dai, substream, rollback);
> + return;
> + }
> +
> + substream->stream = stream;
> + snd_soc_dai_hw_free(dai, substream, rollback);
> + substream->stream = saved_stream;
> +}
[Severity: Medium]
Can flipping be_substream->stream in soc_pcm_dai_hw_free_at_stream() race
with dpcm_be_dai_trigger()?
When two playback FEs (FE1, FE2) share a multi_direction_codecs BE (BE1)
and FE2 is also routed to a second BE (BE2), FE1 can be in
SND_SOC_DPCM_STATE_PREPARE while FE2 transitions BE1 to
SND_SOC_DPCM_STATE_STOP and then fails hw_params on BE2. Unlike
dpcm_be_dai_hw_free(), the unwind loop in dpcm_be_dai_hw_params() does not
skip BEs with users > 1 and allows SND_SOC_DPCM_STATE_STOP, so it calls
__soc_pcm_hw_free() under pcm_mutex without holding be_substream's stream
lock:
CPU0 (FE2 hw_params unwind) CPU1 (FE1 trigger start)
dpcm_be_dai_hw_params()
lock(&card->pcm_mutex)
__soc_pcm_hw_free(BE1, ...)
soc_pcm_dai_hw_free_at_stream()
be_substream->stream = CAPTURE
dai->ops->hw_free() (sleeps)
dpcm_be_dai_trigger(FE1, ...)
/* no pcm_mutex */
soc_pcm_trigger(be_substream, ...)
soc_dai_trigger()
reads be_substream->stream
<-- sees capture
Observing capture makes soc_dai_trigger() silently skip the playback-only
CPU and codec DAIs while still marking BE1 as started, and dispatches
SNDRV_PCM_TRIGGER_START to the capture-only codec DAIs.
> +/* DAPM counterpart, so the DAI's own direction widget gets updated */
> +static void soc_pcm_dapm_update_dai_at_stream(struct snd_pcm_substream *substream,
> + struct snd_pcm_hw_params *params,
> + struct snd_soc_dai *dai, int stream)
> +{
> + int saved_stream = substream->stream;
> +
> + substream->stream = stream;
> + snd_soc_dapm_update_dai(substream, params, dai);
> + substream->stream = saved_stream;
> +}
[Severity: Medium]
Should soc_pcm_dapm_update_dai_at_stream() check stream == saved_stream, or
pass stream directly to snd_soc_dapm_update_dai()?
Unlike its sibling helpers above, this function unconditionally writes
substream->stream twice for every codec DAI on every ASoC link, even when
multi_direction_codecs is not set. ALSA core paths such as snd_pcm_info()
and snd_pcm_poll() read substream->stream without card->pcm_mutex, so this
introduces a data race across all ASoC links.
Since snd_soc_dapm_update_dai() is an unexported helper whose callee
dapm_update_dai_unlocked() only copies substream->stream into a local dir
variable, passing stream as a parameter would avoid mutating
substream->stream altogether.
[ ... ]
> @@ -1053,6 +1113,10 @@ static int soc_pcm_hw_clean(struct snd_soc_pcm_runtime *rtd,
>
> /* run the stream event */
> snd_soc_dapm_stream_stop(rtd, substream->stream);
> + /* Flip only codec-side widgets; see __soc_pcm_prepare(). */
> + if (rtd->dai_link->multi_direction_codecs)
> + snd_soc_dapm_codec_stream_event(rtd, substream->stream ^ 1,
> + SND_SOC_DAPM_STREAM_STOP);
[Severity: Medium]
Does this power down the opposite-direction codec widgets prematurely when
pmdown_time is active?
For playback streams without ignore_pmdown_time, snd_soc_dapm_stream_stop()
defers SND_SOC_DAPM_STREAM_STOP to rtd->delayed_work
(snd_soc_close_delayed_work()), whereas this call stops the companion codec
widgets synchronously in hw_free. Moving the multi_direction_codecs
handling into dapm_stream_event() would keep both directions aligned with
pmdown_time.
[ ... ]
> @@ -1148,13 +1245,15 @@ static int __soc_pcm_hw_params(struct snd_pcm_substream *substream,
> if (ch_mask)
> soc_pcm_codec_params_fixup(&tmp_params, ch_mask);
>
> - ret = snd_soc_dai_hw_params(codec_dai, substream,
> - &tmp_params);
> - if(ret < 0)
> + ret = soc_pcm_dai_hw_params_at_stream(codec_dai, substream,
> + &tmp_params,
> + codec_stream);
> + if (ret < 0)
> goto out;
>
> snd_soc_dai_symmetric_set_params(codec_dai, &tmp_params);
> - snd_soc_dapm_update_dai(substream, &tmp_params, codec_dai);
> + soc_pcm_dapm_update_dai_at_stream(substream, &tmp_params,
> + codec_dai, codec_stream);
> }
[Severity: Medium]
Can calling snd_soc_dai_symmetric_set_params() on a direction-flipped codec
DAI contaminate symmetry constraints for later playback streams?
Because __soc_pcm_open() marks every DAI on the link active and
snd_soc_dai_symmetric_apply() checks snd_soc_dai_active(dai) without
filtering by direction, storing rewritten opposite-direction params (such as
8 kHz / S32_LE from multi_direction_params_fixup) into codec_dai causes a
second stream opening the link to inherit those values as single-value
constraints when symmetric_{rate,channels,sample_bits} is enabled, failing
open with -EINVAL. This also contradicts the note in
Documentation/sound/soc/multi-direction-codecs.rst claiming symmetric-params
tracking cannot cross-contaminate.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=2
next prev parent reply other threads:[~2026-12-04 12:01 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
2026-12-04 12:01 ` sashiko-bot [this message]
2026-12-04 11:30 ` [PATCH v5 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
2026-12-04 12:12 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
2026-12-04 12:38 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
2026-12-04 12:33 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
2026-12-04 13:34 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
2026-12-04 13:35 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
2026-12-04 13:32 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
2026-12-04 13:32 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
2026-12-04 13:25 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
2026-12-04 13:43 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
2026-12-04 13:50 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
2026-12-04 14:01 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
2026-12-04 13:56 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
2026-12-04 14:04 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
2026-12-04 13:59 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
2026-12-04 14:11 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
2026-12-04 14:16 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
2026-12-04 14:18 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
2026-12-04 14:16 ` sashiko-bot
2026-12-04 11:31 ` [PATCH v5 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
2026-12-04 14:24 ` sashiko-bot
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-249742@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=srinivas.kandagatla@oss.qualcomm.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.