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=1796075941; b=xKv+bZ0mZkUixAybxfiAEmOVSrfXp/sbVsb5F4MIO9KPJ+xgP8/XehjEpFVNnOkmCTYq ZuidNayhT6ZZGSmXWDRvXSctiqR/E0BBsIkAPACNCyQ/HE5QkWa+NpXueEnxtLbuSFDAd /DFVzjgcjSLsAQj8HJNKzPHqmCgOW6ZHgDrt+CuoJsyQAdivCiZTJBy/YJIUVXtO6jV5s xHeuFsYM+3r04EARnGquud1kC9RtGVTZpkrxAnAmVDM0sTKJ9fuPf2ymoncAbjVysClyj yx8NxUa2HIJBJzm5Jdp0WYet6ny5pardtq7Jy9sMw/X+x5r7uxE/Si+uM2Y5JedmneQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796075941; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=erYrclhAaCltkCGycOymQiSptUGnv6lgREUvwSDvCQM=; b=QcKdPN3udJqcGDlD2hsbVfckRgDnbJZFd9jzytabYtYRBQItTykbxLikW6svlrKHzafV r0jiyjqTKNxUw49TrboaN56QsCsnbzZEkomyk9mxiFGGA2yUFlHomE+s/C/MHsu3qK0xp 57o019qS9U3vANJqMXXukqNt2voJwgHbqKOxlM0PeNYYB13aVUJhsQPIOg8FdPAC/GJOJ eQSgks+ZKtrh/wNzUK2dMuPXfjTH1HjnjywqjajUZWbmCwd/SRgfXUbGuztwdq3a9B6zr HdeS/F6d6N2KnDOpVqbpd8V9gHGPLEB87R7J21EbZbcq3AcbjaF7zTbshj29ZWg3tjg== 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=HcMcSlsF; 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 C144E606A31A; Mon, 30 Nov 2026 21:59:01 +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=HcMcSlsF Received: by smtp.kernel.org (Postfix) with ESMTPSA id E37141F0092C; Mon, 30 Nov 2026 21:59:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796075941; bh=erYrclhAaCltkCGycOymQiSptUGnv6lgREUvwSDvCQM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=HcMcSlsFl+qAphTuTrZF6V4Igbu5wu6BJiZtaNKRDPBhr/nhHk3NIkf7mlg907s28 hzUbcZukaGEEjNJpLdJAENodVfA0Ua37ta2q/hEI9hmV+MnR2gRmu/vJ8RKB+NUf3I AJXg04n11YcKRpeBk02s36uBgu96Ca7BS/cobzfG6CLE2kyAlWB1DGRg/BFTiizKrZ YxJ4C//UEE3QQuDXmTqzAveqy8mrJdyXuseF3VuFSZn7FTg+WtIBcNwoYyhgk2qCbK 7kUhaij7i8lHQ3EoohuPcP27sBanxf+pDnlls6uePwwYq8b60JyAoNDf8SqDuhAI6Y JRks5Qgbv9+Lw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links 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: <20261130212258.7376-5-srinivas.kandagatla@oss.qualcomm.com> References: <20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com> <20261130212258.7376-5-srinivas.kandagatla@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 21:59:00 +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 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 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 > #include > #include > +#include > #include > #include "sdw.h" > =20 > +static struct sdw_stream_runtime * > +qcom_snd_sdw_alloc_stream(const char *cpu_name, int dir) > +{ > + const char *suffix =3D (dir =3D=3D SNDRV_PCM_STREAM_PLAYBACK) ? > + "Playback" : "Capture"; > + struct sdw_stream_runtime *sr; > + char *name; > + > + name =3D kasprintf(GFP_KERNEL, "%s-%s", cpu_name, suffix); > + if (!name) > + return NULL; > + > + sr =3D 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 =3D 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; > } > =20 > -/** > - * qcom_snd_sdw_startup() - Helper to start Soundwire stream for SoC aud= io card > - * @substream: The PCM substream from audio, as passed to snd_soc_ops->s= tartup() > - * > - * Helper for the SoC audio card (snd_soc_ops->startup()) to allocate an= d 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 D= AIs > + * 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 d= ir) > { > - struct snd_soc_pcm_runtime *rtd =3D snd_soc_substream_to_rtd(substream); > - struct snd_soc_dai *cpu_dai =3D snd_soc_rtd_to_cpu(rtd, 0); > - u32 rx_ch[SDW_MAX_PORTS], tx_ch[SDW_MAX_PORTS]; > + const char *cpu_name =3D 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 =3D 0, tx_ch_cnt =3D 0; > int ret, i, j; > + bool used =3D false; > =20 > - 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 =3D true; > + break; > + } > + } > + if (!used) > return 0; > =20 > - sruntime =3D sdw_alloc_stream(cpu_dai->name, SDW_STREAM_PCM); > + sruntime =3D qcom_snd_sdw_alloc_stream(cpu_name, dir); > if (!sruntime) > return -ENOMEM; > =20 > for_each_rtd_codec_dais(rtd, i, codec_dai) { > - ret =3D snd_soc_dai_set_stream(codec_dai, sruntime, > - substream->stream); > + if (!snd_soc_dai_stream_valid(codec_dai, dir)) > + continue; > + > + ret =3D snd_soc_dai_set_stream(codec_dai, sruntime, dir); > if (ret < 0 && ret !=3D -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 =3D=3D -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 =3D <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 aud= io card > + * @substream: The PCM substream from audio, as passed to snd_soc_ops->s= tartup() > + * > + * Helper for the SoC audio card (snd_soc_ops->startup()) to allocate an= d 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 =3D sdw_enable_stream(sruntime); > - if (ret) { > - sdw_deprepare_stream(sruntime); > + ret =3D 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 =3D > + 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 !=3D SDW_STREAM_ALLOCATED) { > + ret =3D qcom_snd_sdw_prepare_dir(rtd, > + substream->stream ^ 1); > + if (ret) { > + struct sdw_stream_runtime *sr =3D > + sdw_find_dir_stream(rtd, substream->stream); > + if (sr) { > + sdw_disable_stream(sr); > + sdw_deprepare_stream(sr); > + } > + return ret; > + } > + } > } > - *stream_prepared =3D true; > =20 > - return ret; > + *stream_prepared =3D true; > + return 0; > } > EXPORT_SYMBOL_GPL(qcom_snd_sdw_prepare); > =20 > @@ -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 =3D snd_soc_substream_to_rtd(substream); > struct snd_soc_dai *cpu_dai =3D snd_soc_rtd_to_cpu(rtd, 0); > - struct sdw_stream_runtime *sruntime; > + struct sdw_stream_runtime *sr; > =20 > if (!qcom_snd_is_sdw_dai(cpu_dai->id)) > return 0; > =20 > - sruntime =3D qcom_snd_sdw_get_stream(substream); > - if (sruntime && *stream_prepared) { > - sdw_disable_stream(sruntime); > - sdw_deprepare_stream(sruntime); > - *stream_prepared =3D false; > + if (!*stream_prepared) > + return 0; > + > + sr =3D 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 =3D sdw_find_dir_stream(rtd, substream->stream ^ 1); > + if (sr && sr->state !=3D SDW_STREAM_ALLOCATED) { > + sdw_disable_stream(sr); > + sdw_deprepare_stream(sr); > + } > } > =20 > + *stream_prepared =3D 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 =3D 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 !=3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130212258.7376= -1-srinivas.kandagatla@oss.qualcomm.com?part=3D4