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 v3 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links
Date: Mon, 30 Nov 2026 21:59:00 +0000 [thread overview]
Message-ID: <sashiko-outbox-242058@kernel.org> (raw)
In-Reply-To: <20261130212258.7376-5-srinivas.kandagatla@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] ASoC: qcom: sdw: stream runtime and name leak in
qcom_snd_sdw_setup_dir()
- [Medium] ASoC: qcom: sdw: prepare failure after hw_free sets
SDW_STREAM_RELEASED
- [Low] ASoC: qcom: sdw: un-updated qcom_snd_sdw_get_stream() and
startup kernel-doc
--
commit a22b440aefca0499037c2fa2afd6614e48af6f03
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links
This commit splits SoundWire stream startup, prepare, hw_free, and shutdown
into per-direction helpers so that links with multi_direction_codecs
allocate and manage a separate sdw_stream_runtime for each direction.
> diff --git a/sound/soc/qcom/sdw.c b/sound/soc/qcom/sdw.c
> index 6576b47a4c8c3..82f1c47a788cb 100644
> --- a/sound/soc/qcom/sdw.c
> +++ b/sound/soc/qcom/sdw.c
> @@ -5,9 +5,55 @@
> #include <dt-bindings/sound/qcom,lpass.h>
> #include <dt-bindings/sound/qcom,q6afe.h>
> #include <linux/module.h>
> +#include <linux/slab.h>
> #include <sound/soc.h>
> #include "sdw.h"
>
> +static struct sdw_stream_runtime *
> +qcom_snd_sdw_alloc_stream(const char *cpu_name, int dir)
> +{
> + const char *suffix = (dir == SNDRV_PCM_STREAM_PLAYBACK) ?
> + "Playback" : "Capture";
> + struct sdw_stream_runtime *sr;
> + char *name;
> +
> + name = kasprintf(GFP_KERNEL, "%s-%s", cpu_name, suffix);
> + if (!name)
> + return NULL;
> +
> + sr = sdw_alloc_stream(name, SDW_STREAM_PCM);
> + if (!sr) {
> + kfree(name);
> + return NULL;
> + }
> + return sr;
> +}
> +
> +static void qcom_snd_sdw_release_stream(struct sdw_stream_runtime *sr)
> +{
> + if (!sr)
> + return;
> + kfree(sr->name);
> + sdw_release_stream(sr);
> +}
> +
> +static struct sdw_stream_runtime *
> +sdw_find_dir_stream(struct snd_soc_pcm_runtime *rtd, int dir)
> +{
> + struct snd_soc_dai *codec_dai;
> + struct sdw_stream_runtime *sr;
> + int i;
> +
> + for_each_rtd_codec_dais(rtd, i, codec_dai) {
> + if (!snd_soc_dai_stream_valid(codec_dai, dir))
> + continue;
> + sr = snd_soc_dai_get_stream(codec_dai, dir);
> + if (!IS_ERR(sr) && sr)
> + return sr;
> + }
> + return NULL;
> +}
[ ... ]
> @@ -49,43 +95,42 @@ static bool qcom_snd_is_sdw_dai(int id)
> return false;
> }
>
> -/**
> - * qcom_snd_sdw_startup() - Helper to start Soundwire stream for SoC audio card
> - * @substream: The PCM substream from audio, as passed to snd_soc_ops->startup()
> - *
> - * Helper for the SoC audio card (snd_soc_ops->startup()) to allocate and set
> - * Soundwire stream runtime to each codec DAI.
> - *
> - * The shutdown() callback should call sdw_release_stream() on the same
> - * sdw_stream_runtime.
> - *
> - * Return: 0 or errno
> +/*
> + * Allocate a stream runtime for one direction and set it on the codec DAIs
> + * of that direction.
> */
> -int qcom_snd_sdw_startup(struct snd_pcm_substream *substream)
> +static int qcom_snd_sdw_setup_dir(struct snd_soc_pcm_runtime *rtd, int dir)
> {
> - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
> - struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
> - u32 rx_ch[SDW_MAX_PORTS], tx_ch[SDW_MAX_PORTS];
> + const char *cpu_name = snd_soc_rtd_to_cpu(rtd, 0)->name;
> struct sdw_stream_runtime *sruntime;
> struct snd_soc_dai *codec_dai;
> + u32 rx_ch[SDW_MAX_PORTS], tx_ch[SDW_MAX_PORTS];
> u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
> int ret, i, j;
> + bool used = false;
>
> - if (!qcom_snd_is_sdw_dai(cpu_dai->id))
> + for_each_rtd_codec_dais(rtd, i, codec_dai) {
> + if (snd_soc_dai_stream_valid(codec_dai, dir)) {
> + used = true;
> + break;
> + }
> + }
> + if (!used)
> return 0;
>
> - sruntime = sdw_alloc_stream(cpu_dai->name, SDW_STREAM_PCM);
> + sruntime = qcom_snd_sdw_alloc_stream(cpu_name, dir);
> if (!sruntime)
> return -ENOMEM;
>
> for_each_rtd_codec_dais(rtd, i, codec_dai) {
> - ret = snd_soc_dai_set_stream(codec_dai, sruntime,
> - substream->stream);
> + if (!snd_soc_dai_stream_valid(codec_dai, dir))
> + continue;
> +
> + ret = snd_soc_dai_set_stream(codec_dai, sruntime, dir);
> if (ret < 0 && ret != -ENOTSUPP) {
> dev_err(rtd->dev, "Failed to set sdw stream on %s\n", codec_dai->name);
> - goto err_set_stream;
> + goto err;
> } else if (ret == -ENOTSUPP) {
> - /* Ignore unsupported */
> continue;
> }
[Severity: High]
Does qcom_snd_sdw_setup_dir() leak sruntime and sruntime->name when none
of the stream-valid codec DAIs in dir implement .get_stream?
qcom_snd_sdw_setup_dir() allocates sruntime whenever any codec DAI is
stream-valid for dir, skips codec DAIs that are not stream-valid for dir,
and ignores -ENOTSUPP from snd_soc_dai_set_stream(). At shutdown,
qcom_snd_sdw_shutdown() relies on sdw_find_dir_stream(rtd, dir) to find
and free sruntime, which only queries stream-valid codec DAIs via
snd_soc_dai_get_stream().
On Qualcomm platforms, only the qcom_swrm master DAI implements
.get_stream; slave codecs only implement .set_stream, and LPASS macro
codec DAIs return -ENOTSUPP. On links where no codec DAI in dir supports
SoundWire streams (such as TX_CODEC_DMA_TX_3 with lpass_vamacro on
va-dai-link), or on WCD capture links where the swr master DAI is
registered as playback-only (such as <&swr2 0> when qcom,dout-ports = <1>
on sm8650 and sm8750) and is skipped by snd_soc_dai_stream_valid(),
sdw_find_dir_stream() returns NULL and leaks sruntime and sruntime->name
on every open/close cycle (while also leaving the stream unset on
<&swr2 0>).
> @@ -93,59 +138,106 @@ int qcom_snd_sdw_startup(struct snd_pcm_substream *substream)
[ ... ]
> +/**
> + * qcom_snd_sdw_startup() - Helper to start Soundwire stream for SoC audio card
> + * @substream: The PCM substream from audio, as passed to snd_soc_ops->startup()
> + *
> + * Helper for the SoC audio card (snd_soc_ops->startup()) to allocate and set
> + * Soundwire stream runtime to each codec DAI.
> + *
> + * The shutdown() callback should call sdw_release_stream() on the same
> + * sdw_stream_runtime.
> + *
> + * Return: 0 or errno
> + */
[Severity: Low]
This isn't a bug, but this patch replaces all in-tree callers of
qcom_snd_sdw_get_stream() with sdw_find_dir_stream(), leaving the
exported qcom_snd_sdw_get_stream() unused and still open-coding the
codec DAI loop without checking snd_soc_dai_stream_valid() (which can
return the wrong direction's stream on a multi_direction_codecs link
because qcom_swrm_get_sdw_stream() ignores its direction argument).
Also, the kernel-doc above still tells callers to use
sdw_release_stream() in shutdown() instead of qcom_snd_sdw_shutdown(),
which would leak sr->name and the opposite-direction stream.
[ ... ]
> @@ -153,15 +245,32 @@ int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream,
> * accumulated resulting in Click/Pop Noise
> * PA enable/mute are handled as part of codec DAPM and digital mute.
> */
> -
> - ret = sdw_enable_stream(sruntime);
> - if (ret) {
> - sdw_deprepare_stream(sruntime);
> + ret = qcom_snd_sdw_prepare_dir(rtd, substream->stream);
> + if (ret)
> return ret;
> +
> + if (rtd->dai_link->multi_direction_codecs) {
> + struct sdw_stream_runtime *sr_opp =
> + sdw_find_dir_stream(rtd, substream->stream ^ 1);
> +
> + /* Skip if no slave registered at hw_params (e.g. VI off) */
> + if (sr_opp && sr_opp->state != SDW_STREAM_ALLOCATED) {
> + ret = qcom_snd_sdw_prepare_dir(rtd,
> + substream->stream ^ 1);
> + if (ret) {
> + struct sdw_stream_runtime *sr =
> + sdw_find_dir_stream(rtd, substream->stream);
> + if (sr) {
> + sdw_disable_stream(sr);
> + sdw_deprepare_stream(sr);
> + }
> + return ret;
> + }
> + }
> }
> - *stream_prepared = true;
>
> - return ret;
> + *stream_prepared = true;
> + return 0;
> }
> EXPORT_SYMBOL_GPL(qcom_snd_sdw_prepare);
>
> @@ -187,9 +296,13 @@ EXPORT_SYMBOL_GPL(qcom_snd_sdw_get_stream);
[ ... ]
> @@ -197,18 +310,29 @@ int qcom_snd_sdw_hw_free(struct snd_pcm_substream *substream, bool *stream_prepa
> {
> struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
> struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
> - struct sdw_stream_runtime *sruntime;
> + struct sdw_stream_runtime *sr;
>
> if (!qcom_snd_is_sdw_dai(cpu_dai->id))
> return 0;
>
> - sruntime = qcom_snd_sdw_get_stream(substream);
> - if (sruntime && *stream_prepared) {
> - sdw_disable_stream(sruntime);
> - sdw_deprepare_stream(sruntime);
> - *stream_prepared = false;
> + if (!*stream_prepared)
> + return 0;
> +
> + sr = sdw_find_dir_stream(rtd, substream->stream);
> + if (sr) {
> + sdw_disable_stream(sr);
> + sdw_deprepare_stream(sr);
> + }
> +
> + if (rtd->dai_link->multi_direction_codecs) {
> + sr = sdw_find_dir_stream(rtd, substream->stream ^ 1);
> + if (sr && sr->state != SDW_STREAM_ALLOCATED) {
> + sdw_disable_stream(sr);
> + sdw_deprepare_stream(sr);
> + }
> }
>
> + *stream_prepared = false;
> return 0;
> }
> EXPORT_SYMBOL_GPL(qcom_snd_sdw_hw_free);
[Severity: Medium]
Can qcom_snd_sdw_prepare() fail with -EINVAL on a second hw_params/prepare
cycle when no slave registers on sr_opp?
During hw_params on a multi_direction_codecs link, qcom_swrm_hw_params()
adds the master runtime to sr_opp->master_list even when the opposite-
direction slave (such as VI sense) is off and does not call
sdw_stream_add_slave(). When hw_free later runs on that open substream,
qcom_swrm_hw_free() calls sdw_stream_remove_master(), which sets
sr_opp->state to SDW_STREAM_RELEASED:
drivers/soundwire/stream.c:sdw_stream_remove_master() {
...
if (list_empty(&stream->master_list))
stream->state = SDW_STREAM_RELEASED;
...
}
If another hw_params and prepare cycle runs on the same open substream
while VI sense is still off, sr_opp->state remains SDW_STREAM_RELEASED.
Both qcom_snd_sdw_prepare() and qcom_snd_sdw_hw_free() only check
state != SDW_STREAM_ALLOCATED, so qcom_snd_sdw_prepare() calls
sdw_prepare_stream(sr_opp) in SDW_STREAM_RELEASED state, which returns
-EINVAL and tears down the primary stream.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=4
next prev parent reply other threads:[~2026-11-30 21:59 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
2026-11-30 23:18 ` Kuninori Morimoto
2026-11-30 21:22 ` [PATCH v3 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
2026-11-30 21:59 ` sashiko-bot [this message]
2026-11-30 21:22 ` [PATCH v3 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
2026-11-30 21:36 ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
2026-11-30 21:36 ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
2026-11-30 21:39 ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
2026-11-30 21:41 ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
2026-11-30 21:31 ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
2026-11-30 21:34 ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
2026-11-30 21:36 ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
2026-11-30 21:41 ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
2026-11-30 21:39 ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
2026-11-30 21:47 ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
2026-11-30 21:41 ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
2026-11-30 21:43 ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
2026-11-30 21:43 ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
2026-11-30 21:45 ` sashiko-bot
2026-12-01 12:04 ` [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Mark Brown
2026-12-01 12:06 ` Srinivas Kandagatla
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-242058@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.