Linux Sound subsystem development
 help / color / mirror / Atom feed
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 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format
Date: Fri, 04 Dec 2026 13:56:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-249908@kernel.org> (raw)
In-Reply-To: <20261204113101.1141644-18-srinivas.kandagatla@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] ASoC: qcom: TOCTOU race on sp_operation_mode across SP and VI
  modules
- [Medium] ASoC: qcom: heap OOB read in
  audioreach_speaker_protection_send_static_cfg()
- [Low] ASoC: qcom: dead sp_vi_cfg overrides in
  audioreach_set_media_format()
--

commit 2e9d1aaa9d032e965bfa3fbbc815b46ec62787a1
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>

ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format

This commit overrides the sample rate and bit width to 8 kHz and 32 bits in
audioreach_set_media_format() for MODULE_ID_SPEAKER_PROTECTION_VI and for
any MODULE_ID_CODEC_DMA_SOURCE in a subgraph containing it.

> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index fd803d6ceccd0..d1f6cd2b66354 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
> @@ -2064,12 +2064,41 @@ static int audioreach_speaker_protection_vi_static_cfg(struct q6apm_graph *graph
>  	return audioreach_speaker_protection_send_static_cfg(graph, module, "VI");
>  }

[Severity: Medium]
Can audioreach_speaker_protection_send_static_cfg() read past the end of
module->data when size is not a multiple of 4?

audioreach_get_module_priv_data() truncates the allocation to whole __le32
words while keeping the unrounded byte count in pdata->size:

sound/soc/qcom/qdsp6/topology.c:audioreach_get_module_priv_data() {
	...
	nwords = array_size / sizeof(__le32);
	...
	pdata = kzalloc_flex(*pdata, data, nwords);
	...
}

When a speaker protection topology blob has a non-4-byte-aligned size,
audioreach_speaker_protection_send_static_cfg() hits its size % sizeof(u32)
fallback and passes the unrounded size to
audioreach_speaker_protection_send_chunk(), where memcpy() reads 1 to 3
bytes past the allocated slab object and sends them to the DSP.

[ ... ]

>  int audioreach_set_media_format(struct q6apm_graph *graph,
>  				const struct audioreach_module *module,
>  				const struct audioreach_module_config *cfg)
>  {
> +	struct audioreach_module_config sp_vi_cfg;
>  	int rc;
>  
> +	/* The VI module and its codec DMA source always run at 8 kHz, S32_LE */
> +	if (module->module_id == MODULE_ID_SPEAKER_PROTECTION_VI ||
> +	    (module->module_id == MODULE_ID_CODEC_DMA_SOURCE &&
> +	     audioreach_sg_contains_sp_vi(module->container ?
> +					  module->container->sub_graph : NULL))) {
> +		sp_vi_cfg = *cfg;
> +		sp_vi_cfg.sample_rate = 8000;
> +		sp_vi_cfg.bit_width = 32;
> +		sp_vi_cfg.bits_per_sample = 32;
> +		cfg = &sp_vi_cfg;
> +	}

[Severity: Low]
Are the MODULE_ID_SPEAKER_PROTECTION_VI check and the bits_per_sample
assignment needed here?

audioreach_speaker_protection_vi() only reads num_channels and
channel_map[] from cfg, ignoring sample_rate, bit_width, and
bits_per_sample, so copying *cfg for the VI module has no effect.
audioreach_codec_dma_set_media_format() also never reads bits_per_sample
(nothing in sound/soc/qcom/qdsp6/ does).

>  
>  	switch (module->module_id) {

[Severity: Medium]
Can the speaker protection and VI modules in the same graph be programmed
with mismatched sp_operation_mode values?

q6apm_graph_media_format_pcm() calls audioreach_set_media_format() for each
module in sequence without snapshotting sp_operation_mode, and the SP and
VI handlers each perform an independent READ_ONCE() across sleeping DSP IPC
calls:

CPU0                                 CPU1
q6apm_graph_media_format_pcm()
  audioreach_set_media_format(SP)
    audioreach_speaker_protection()
      READ_ONCE(sp_operation_mode)
      /* sees Normal, sends IPC */
                                     audioreach_trigger_sp_calibration()
                                       /* switches to Calibration */
  audioreach_set_media_format(VI)
    audioreach_speaker_protection_vi()
      READ_ONCE(sp_operation_mode)   <-- sees Calibration

If calibration is triggered (or the calibration watchdog fires) during this
window, the coupled SP and VI modules end up in opposite modes, breaking
speaker protection or calibration.  Snapshotting sp_operation_mode once per
graph prepare pass would keep both modules consistent.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=17

  reply	other threads:[~2026-12-04 13:56 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
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 [this message]
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-249908@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