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 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links
Date: Fri, 04 Dec 2026 12:12:33 +0000 [thread overview]
Message-ID: <sashiko-outbox-249765@kernel.org> (raw)
In-Reply-To: <20261204113101.1141644-5-srinivas.kandagatla@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] ASoC: qcom: sdw: leak and skipped master DAI in
qcom_snd_sdw_setup_dir()
- [High] ASoC: soc-dai: NULL ops dereference in
snd_soc_dai_get/set_stream()
- [High] ASoC: qcom: missing qcom_snd_is_sdw_dai() guard in
qcom_snd_sdw_shutdown()
- [Medium] ASoC: qcom: sdw: state check misses SDW_STREAM_RELEASED after
hw_free
- [Low] ASoC: qcom: sdw: un-updated qcom_snd_sdw_get_stream() and
startup kernel-doc
- [Low] ASoC: qcom: sdw: stale sdw_release_stream() doc in
qcom_snd_sdw_startup()
--
commit 4ced7dc60766c6a8522f7fc64244cb10f6e35c6f
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links
This commit splits the Qualcomm SoundWire startup, prepare, hw_free, and
shutdown helpers into per-direction operations so that multi_direction_codecs
links allocate and manage separate sdw_stream_runtime instances for playback
and capture. It also adds a sdw_find_dir_stream() helper and suffixes
allocated stream names with "-Playback" or "-Capture".
> diff --git a/sound/soc/qcom/sdw.c b/sound/soc/qcom/sdw.c
> index e19adb7c750b0..35b35f43d6fed 100644
> --- a/sound/soc/qcom/sdw.c
> +++ b/sound/soc/qcom/sdw.c
[ ... ]
> +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;
> +}
[Severity: High]
Can calling snd_soc_dai_get_stream() here cause a NULL pointer dereference
when a codec DAI leaves dai->driver->ops as NULL?
Unlike the other helpers in sound/soc/soc-dai.c, snd_soc_dai_get_stream()
and snd_soc_dai_set_stream() dereference dai->driver->ops->get_stream and
->set_stream without checking dai->driver->ops for NULL. Because
qcom_snd_sdw_shutdown() now calls sdw_find_dir_stream() without checking
qcom_snd_is_sdw_dai(), closing speaker playback on QCS8550 boards using
aw88166 (which has .ops == NULL on PRIMARY_MI2S_RX in
qcs8550-ayntec-common.dtsi) dereferences NULL dai->driver->ops and oopses.
[ ... ]
> @@ -50,43 +96,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 filtering by snd_soc_dai_stream_valid() here skip direction-mismatched
SoundWire master DAIs and leak sruntime and sruntime->name?
On SM8650 WCD Capture (wcd-capture-dai-link in sm8650-hdk.dts), swr2 has
qcom,dout-ports = <1>, so qcom_swrm_register_dais() registers DAI 0
(<&swr2 0>) as playback-only. Previously <&swr2 0> still received and
returned sruntime, whereas now both qcom_snd_sdw_setup_dir() and
sdw_find_dir_stream() skip it, breaking master stream assignment and leaving
sdw_find_dir_stream() to return NULL at shutdown because <&wcd939x 1> has no
.get_stream.
Links that match qcom_snd_is_sdw_dai() but only have non-SoundWire codecs
(such as va-dai-link on TX_CODEC_DMA_TX_3 with <&lpass_vamacro 0> in
sm8550-mtp.dts) also allocate sruntime and its kasprintf()-allocated name
here, skip every codec on -ENOTSUPP, and leak both allocations on every
open/close cycle.
[ ... ]
> +/**
> + * 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]
Should this kernel-doc be updated to say that shutdown() must call
qcom_snd_sdw_shutdown() instead of sdw_release_stream()?
Now that qcom_snd_sdw_alloc_stream() allocates sr->name with kasprintf()
and qcom_snd_sdw_startup() can allocate a second runtime on
multi_direction_codecs links, calling sdw_release_stream() directly leaks
sr->name and any opposite-direction stream runtime.
[ ... ]
> + 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;
> + }
> + }
> }
[Severity: Medium]
Does checking sr_opp->state != SDW_STREAM_ALLOCATED fail on a second
hw_params/prepare cycle after hw_free when no opposite-direction slave
registers?
During hw_free (or hw_params error rollback), qcom_swrm_hw_free() calls
sdw_stream_remove_master(), which sets sr_opp->state to SDW_STREAM_RELEASED
once master_list is empty rather than back to SDW_STREAM_ALLOCATED. On the
next hw_params without an opposite-direction slave (for example, V/I sense
disabled), sdw_stream_add_master() leaves sr_opp->state as
SDW_STREAM_RELEASED, so qcom_snd_sdw_prepare() calls
sdw_prepare_stream(sr_opp), which fails with -EINVAL and tears down the
primary stream.
qcom_snd_sdw_hw_free() uses the same sr->state != SDW_STREAM_ALLOCATED
guard, so it can also invoke sdw_disable_stream() and sdw_deprepare_stream()
on an unprepared opposite-direction stream in SDW_STREAM_RELEASED or
SDW_STREAM_CONFIGURED state.
[ ... ]
> @@ -188,9 +299,16 @@ EXPORT_SYMBOL_GPL(qcom_snd_sdw_get_stream);
[Severity: Low]
Should qcom_snd_sdw_get_stream() also delegate to sdw_find_dir_stream()
instead of keeping its open-coded loop?
qcom_swrm_get_sdw_stream() ignores its direction argument and returns
ctrl->sruntime[dai->id], so without snd_soc_dai_stream_valid() filtering,
qcom_snd_sdw_get_stream() can return the opposite direction's stream on
multi_direction_codecs links. The startup kernel-doc also still directs
callers to sdw_release_stream() rather than qcom_snd_sdw_shutdown().
> void qcom_snd_sdw_shutdown(struct snd_pcm_substream *substream)
> {
> - struct sdw_stream_runtime *sruntime = qcom_snd_sdw_get_stream(substream);
> + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
> +
> + qcom_snd_sdw_release_stream(sdw_find_dir_stream(rtd, substream->stream));
>
> - sdw_release_stream(sruntime);
> + if (rtd->dai_link->multi_direction_codecs) {
> + struct sdw_stream_runtime *sr;
> +
> + sr = sdw_find_dir_stream(rtd, substream->stream ^ 1);
> + qcom_snd_sdw_release_stream(sr);
> + }
> }
> EXPORT_SYMBOL_GPL(qcom_snd_sdw_shutdown);
[Severity: High]
Is a qcom_snd_is_sdw_dai(cpu_dai->id) guard missing at the start of
qcom_snd_sdw_shutdown()?
Previously qcom_snd_sdw_get_stream() returned NULL early for non-SoundWire
CPU DAIs. Because machine drivers like sc8280xp.c attach
qcom_snd_sdw_shutdown() to all BE links, removing that guard causes
sdw_find_dir_stream() to run on non-SoundWire links such as PRIMARY_MI2S_RX
with aw88166 (.ops == NULL) on QCS8550 boards (qcs8550-ayntec-common.dtsi),
triggering a NULL pointer dereference in snd_soc_dai_get_stream() while
closing PCM playback.
If any non-SoundWire codec DAI implements .get_stream, this would also pass
that foreign pointer to qcom_snd_sdw_release_stream() and free memory that
qcom_snd_sdw_startup() never allocated.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=4
next prev parent reply other threads:[~2026-12-04 12:12 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
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 [this message]
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-249765@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox