From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385676; b=AFlsNTj9UAwERzK+rsLVKZDio061dBrec7tcyh93tH1fY55mGHSurL0Hb1xofVtakd1W MRAykIf8hJxlH8cbWp78N6oSuy+WMs7nrmOqNbnFjpdy8ulzpDv2r30d8hmRoaQHn/tBy AmGDYihxh/869zHd2MOUAlQod/QsZlslQNvVsbD63Dl0PP58Zj7FinlHKl2sLiUkF284F oIdvQO0Azs0LQcM7b2dBYxNOPo+Am0g67EadYvig5kWfIcHXPWRtW472U3XdQqDNuofce e4CRJ6NIfQ4c2roOTA4nwpiELRf/IayHLijdqt8InULTInASUOnqRAVgeZFBtyoHpnA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385676; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=i10HBfSC7AYpkn9bs+1X5IFXNZy+pzHzNX+ejYMff1M=; b=FBJtd2IYWuSAoqzRT4fKS/4g++ptygzbpn9zv7UWfjrrnEasy1vgnW+paIQFe6PAM3VN Up71Wz/4iMkK0dLHUL9BfYpASqbvttfzGTzhc4fCYTkvWHF2ECi92d2qy+D1Z7r6oU6DZ EdEgBFd5p+oOitYKZ6DaAIGjt5hvKkFufdooI9hT5a/jzY+bxmNkOgqqFTpI/l4g80Kmg H+J6oL50xmzA0umebMycdeIwYd/VYqL81eFWwnFHGVf1HPSWJtNycMZcpmS4vmCOUozCm 0N/zhvLx3QToMv8fMcJmDFb9VT1nkAb3cAJBW73Fg527mo4MOfOD79lWpJMc0/iYmBA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RVMa84xb; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7B58606A32F; Fri, 4 Dec 2026 12:01:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RVMa84xb Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4569D1F0092C; Fri, 4 Dec 2026 12:01:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796385676; bh=i10HBfSC7AYpkn9bs+1X5IFXNZy+pzHzNX+ejYMff1M=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=RVMa84xbH0V9iBSJz9sIDadjphi/X5uYlYgCt00EUmCcp6cdXxBUWWGwY7Zc81oDi 3VmrU0S1cD7qAjG3q1sxXuKCRLYFa3sLKvTHq/zRRoWIhzuRZFB4kFujM3sHyppKX+ Wt6EB7mNaWR6IXNOL4oKkR7v2WbNC2UhGzzOx2GARWw/0u28t6naZFh8xhtLFlz3zO TRzPT+XTun3UmghsaTkR84FzWlJR9LsjZ+3mjnsQGQiO2RhyH5A2g0S8YbjYUnC3Ly PfB4RnckqEfV4VEvpsJ7ZJhLndkfsEAM3c9by4XMzTluvqBfbd2BWmIK2PAsU+OrS2 4s/H8PcKGjUxQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Reply-To: sashiko-reviews@lists.linux.dev To: "Srinivas Kandagatla" Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261204113101.1141644-3-srinivas.kandagatla@oss.qualcomm.com> References: <20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com> <20261204113101.1141644-3-srinivas.kandagatla@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 12:01:15 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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/Documen= tation/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 =3D 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_r= untime *rtd, int stream, int e > dapm_power_widgets(rtd->card, event, NULL); > } > =20 > +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); > } > =20 > +/** > + * 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 D= AIs. > + * 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 =3D substream->stream; > + > + if (stream =3D=3D saved_stream) { > + snd_soc_dai_hw_free(dai, substream, rollback); > + return; > + } > + > + substream->stream =3D stream; > + snd_soc_dai_hw_free(dai, substream, rollback); > + substream->stream =3D 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 =3D 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 =3D substream->stream; > + > + substream->stream =3D stream; > + snd_soc_dapm_update_dai(substream, params, dai); > + substream->stream =3D saved_stream; > +} [Severity: Medium] Should soc_pcm_dapm_update_dai_at_stream() check stream =3D=3D 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_run= time *rtd, > =20 > /* 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_sub= stream *substream, > if (ch_mask) > soc_pcm_codec_params_fixup(&tmp_params, ch_mask); > =20 > - ret =3D snd_soc_dai_hw_params(codec_dai, substream, > - &tmp_params); > - if(ret < 0) > + ret =3D soc_pcm_dai_hw_params_at_stream(codec_dai, substream, > + &tmp_params, > + codec_stream); > + if (ret < 0) > goto out; > =20 > 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204113101.1141= 644-1-srinivas.kandagatla@oss.qualcomm.com?part=3D2