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=1796386355; b=R/yP4S2n9kkxbXYWoRSTaK7Q9GaSnHS0FdKMQQd9vfRuLwrmjXVtmTwtgAngX60vg8uL FnzVmTj/qgulPc1Go2+WHbeJl0/KhKP6xvSgpBu1NWAMlvAvTUKSDVux30DhCNQc60uCy or3voGhWh40wNo66waU5bnlUpzO0aFhA5/h06zI0Ye3uSi1R/nLlD2C20fQpL28Ll0JCE BWfIwknV2WXJp/bR2/aZMkjWJxJBIlzWLJGHqQjmXB3vfArauwDIMG1+je2Ogf18WzLPf TOCBpZeI2so4P22AYLA8RV8YX9n7Dqli1E0EunKVcB1rGcAnOS6JFb3dtDceIz4f2ZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386355; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=bHahlYL7gCZH54FwKUw3+Qz0Gx8yP0Bu6OSXOHlIkCo=; b=DLctNt4Wngp49uyAPOmdPy/5UPY2sAIZLBKK6lw4VmsO23mLkpl0zB5HDYbDW2a0X9qU JgpdTOl9cXYGW3Oc/W81UMkRXJsQzJIj96Rmq7PgaKIkdY6GKDXRzCXIYDRiN6xsbWGAL PmsNVK0bpiHA8p20OoCpOb6PrNMRn6SRsDw3xW8GG5Bc4sc5hFBBBnuBu1vH19vpXf7Le MsRdNHCtJ70Y6KzVxaTn2hqLBImfzHA1rkPbaC24PRWyqKGmuA0NamBi0HDCEwWT8LQUd hPng0ohqER5mBPQ2JMyjA43ugXhXKgXOMMTSiWf8hzysppJYdJIrsqIUP/03LjFEGhg== 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=YLNtG0+D; 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 A9F0D606A32F; Fri, 4 Dec 2026 12:12:35 +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=YLNtG0+D Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9B461F000C2; Fri, 4 Dec 2026 12:12:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796386355; bh=bHahlYL7gCZH54FwKUw3+Qz0Gx8yP0Bu6OSXOHlIkCo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=YLNtG0+DO+/+JIT+vUY8aqH4iu/im5ymCFiFgE61fJSfmLR+aONYXvRl/zLAmALX8 cOp03mGMYnDfubkH7kQZzc6LXlkCrSa/akWRYJA7rYuxuvDYnPZwpQhIr4vHn46Eke vaEUme2Rm3HKTqFFH7dWutgwI79gtx0fbtmijnSC8DyKJmem2CjBBJffJDMAiMyhFJ rhFzEFAqfpPa7hGbuhMSn0v6K1dbbPQfYnMV/LBMFfv/eW7tJ+BSBaObV0AZP8++Le wk7YORkbx4U/R3BFbPHcPxaZnGz8ysz2+9bpdKwTdbSV6wgU7zKjofmC7P0KhzbNwl 4lmKin99QWyIg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 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: <20261204113101.1141644-5-srinivas.kandagatla@oss.qualcomm.com> References: <20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com> <20261204113101.1141644-5-srinivas.kandagatla@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 12:12:33 +0000 X-Mailing-List: linux-sound@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 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 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_code= cs 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 =3D 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 =3D=3D 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; > } > =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 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 =3D <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 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] 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 =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; > + } > + } > } [Severity: Medium] Does checking sr_opp->state !=3D 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 !=3D 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 =3D qcom_snd_sdw_get_stream(substre= am); > + struct snd_soc_pcm_runtime *rtd =3D snd_soc_substream_to_rtd(substream); > + > + qcom_snd_sdw_release_stream(sdw_find_dir_stream(rtd, substream->stream)= ); > =20 > - sdw_release_stream(sruntime); > + if (rtd->dai_link->multi_direction_codecs) { > + struct sdw_stream_runtime *sr; > + > + sr =3D 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 =3D=3D NULL) on QCS8550 boards (qcs8550-ayntec-common.dt= si), 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204113101.1141= 644-1-srinivas.kandagatla@oss.qualcomm.com?part=3D4