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 v2 09/24] ASoC: qcom: audioreach: add control link support to graphs
Date: Sun, 22 Nov 2026 16:32:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-228107@kernel.org> (raw)
In-Reply-To: <20261122161437.5994-10-srinivas.kandagatla@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] ASoC: qcom: audioreach: control link packet stride and size
  mismatch
- [Medium] ASoC: qcom: audioreach: num_elems underflow in
  audioreach_parse_cl_tokens()
- [Medium] ASoC: qcom: audioreach: leak of control links on widget load
  error path
--

commit 77f495967e00a276e886e8a3124534923666b6d1
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>

ASoC: qcom: audioreach: add control link support to graphs

This commit parses control link tokens from the topology into a
per-subgraph list and serializes deduplicated control links into the
APM_CMD_GRAPH_OPEN command packet.

> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index aa1f4e2967647..afa8e0159570e 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
> @@ -109,6 +109,26 @@ struct apm_mod_conn_list_params {
>  
>  #define APM_MOD_CONN_PSIZE(p, n) ALIGN(struct_size(p, conn_obj, n), 8)
>  
> +/* Control Links */
> +struct apm_control_link_obj {
> +	u32 peer1_mod_inst_id;
> +	u32 peer1_mod_port_id;
> +	u32 peer2_mod_inst_id;
> +	u32 peer2_mod_port_id;
> +	u32 num_props;
> +	struct apm_prop_data intent_data;
> +	u32 num_intents;
> +	u32 intent_id_list[MAX_INTENTS];
> +} __packed;
> +
> +struct apm_mod_control_links_params {
> +	struct apm_module_param_data param_data;
> +	u32 num_ctrl_link_cfg;
> +	struct apm_control_link_obj link_obj[];
> +} __packed;
> +
> +#define APM_MOD_CTRL_LINK_PSIZE(p, n) ALIGN(struct_size(p, link_obj, n), 8)

[ ... ]

> @@ -442,6 +465,47 @@ static void audioreach_populate_graph(struct q6apm *apm,
>  
>  		apm_populate_sub_graph_config(sg_cfg, sg);
>  
> +		list_for_each_entry(clink, &sg->control_link_list, node) {
> +			bool dup = false;
> +			int k;
> +
> +			/* Both subgraphs usually declare the link, send it once */
> +			for (k = 0; k < nlink; k++) {
> +				struct apm_control_link_obj *o = &cl_data->link_obj[k];
> +
> +				if ((o->peer1_mod_inst_id == clink->peer1_mod_inst_id &&
> +				     o->peer2_mod_inst_id == clink->peer2_mod_inst_id) ||
> +				    (o->peer1_mod_inst_id == clink->peer2_mod_inst_id &&
> +				     o->peer2_mod_inst_id == clink->peer1_mod_inst_id)) {
> +					dup = true;
> +					break;
> +				}
> +			}
> +			if (dup)
> +				continue;
> +
> +			clink_obj = &cl_data->link_obj[nlink++];
> +			clink_obj->peer1_mod_inst_id = clink->peer1_mod_inst_id;
> +			clink_obj->peer1_mod_port_id = clink->peer1_mod_port_id;
> +			clink_obj->peer2_mod_inst_id = clink->peer2_mod_inst_id;
> +			clink_obj->peer2_mod_port_id = clink->peer2_mod_port_id;
> +			clink_obj->intent_data.prop_id = APM_MODULE_PROP_ID_CTRL_LINK_INTENT_LIST;
> +			clink_obj->num_props = 1;
> +			clink_obj->num_intents = 0;
> +
> +			/* Pack the intents that are set into a dense list */
> +			for (j = 0; j < MAX_INTENTS; j++) {
> +				if (clink->intent[j])
> +					clink_obj->intent_id_list[clink_obj->num_intents++] =
> +						clink->intent[j];
> +			}
> +
> +			/* The list length itself is part of the property payload */
> +			clink_obj->intent_data.prop_size =
> +				sizeof(clink_obj->num_intents) +
> +				clink_obj->num_intents * sizeof(clink_obj->intent_id_list[0]);
> +		}

[ ... ]

> @@ -477,12 +541,16 @@ static void audioreach_populate_graph(struct q6apm *apm,
>  			ncontainer++;
>  		}
>  	}
> +
> +	/* The dedupe above may have packed fewer links */
> +	cl_data->num_ctrl_link_cfg = nlink;
>  }

[Severity: High]
Does indexing cl_data->link_obj[nlink++] at a fixed stride misalign
subsequent control links when num_intents is less than MAX_INTENTS?

struct apm_control_link_obj declares intent_id_list[MAX_INTENTS] as a
fixed 4-element array, so link_obj[nlink++] always advances by 48 bytes
even though intent_data.prop_size is set to the packed intent count.
When a link uses fewer than 4 intents and more than one link is packed,
the DSP advances by prop_size and reads the unused zero entries of
intent_id_list[] as the next link's peer IDs, rejecting GRAPH_OPEN.

In addition, audioreach_alloc_graph_pkt() sets param_data->param_size
from the pre-deduplication num_control_links count and fixed MAX_INTENTS
size, and audioreach_populate_graph() updates cl_data->num_ctrl_link_cfg
to nlink without updating cl_data->param_data.param_size.

> diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
> index aa2ab2b058d0f..5dd7f2c51d5cf 100644
> --- a/sound/soc/qcom/qdsp6/topology.c
> +++ b/sound/soc/qcom/qdsp6/topology.c

[ ... ]

> @@ -348,6 +394,85 @@ audioreach_get_module_priv_data(const struct snd_soc_tplg_private *private)
>  	return NULL;
>  }
>  
> +static void audioreach_parse_control_link_tokens(struct q6apm *apm,
> +						 struct audioreach_control_link *link,
> +						 const struct snd_soc_tplg_vendor_array *cl_array)
> +{
> +	const struct snd_soc_tplg_vendor_value_elem *cl_elem = cl_array->value;
> +	int tkn_count = 0;
> +
> +	while (tkn_count <= (le32_to_cpu(cl_array->num_elems) - 1)) {

[ ... ]

> +static void audioreach_parse_cl_tokens(struct q6apm *apm, struct audioreach_sub_graph *sg,
> +				       const struct snd_soc_tplg_private *private)
> +{
> +	const struct snd_soc_tplg_vendor_value_elem *cl_elem;
> +	const struct snd_soc_tplg_vendor_array *cl_array;
> +	struct audioreach_control_link *link;
> +	int link_id, tkn_count, sz;
> +	bool found = false;
> +
> +	for (sz = 0; sz < le32_to_cpu(private->size);) {
> +		cl_array = (struct snd_soc_tplg_vendor_array *)((u8 *)private->array + sz);
> +		cl_elem = cl_array->value;
> +		sz = sz + le32_to_cpu(cl_array->size);
> +		tkn_count = 0;
> +
> +		/* Module config blobs are not token tuples, stop here */
> +		if (le32_to_cpu(cl_array->type) == SND_SOC_AR_TPLG_MODULE_CFG_TYPE)
> +			break;
> +
> +		while (tkn_count <= (le32_to_cpu(cl_array->num_elems) - 1)) {
> +			if (le32_to_cpu(cl_elem->token) == AR_TKN_U32_CONTROL_LINK_IID) {
> +				link_id = le32_to_cpu(cl_elem->value);
> +				link = audioreach_tplg_alloc_control_link(apm, sg, link_id, &found);
> +				/* Skip on error or already parsed control link data */
> +				if (!IS_ERR(link) && !found)
> +					audioreach_parse_control_link_tokens(apm, link, cl_array);
> +			}
> +			tkn_count++;
> +			cl_elem++;
> +		}
> +	}
> +}

[Severity: Medium]
Can le32_to_cpu(cl_array->num_elems) - 1 underflow when a vendor array in
the topology has num_elems == 0?

le32_to_cpu() returns an unsigned u32, so subtracting 1 when num_elems is
0 wraps to U32_MAX, promoting tkn_count to unsigned and reading past the
end of the topology buffer in both audioreach_parse_cl_tokens() and
audioreach_parse_control_link_tokens().

Also, unlike audioreach_get_module_priv_data() right above, the outer
loop does not check for a zero cl_array->size (which would spin forever
because sz never advances), and audioreach_parse_cl_tokens() silently
ignores IS_ERR(link) from audioreach_tplg_alloc_control_link() instead of
propagating the error.

> @@ -617,6 +742,8 @@ static int audioreach_widget_load_module_common(struct snd_soc_component *compon
>  	if (IS_ERR(sg))
>  		return PTR_ERR(sg);
>  
> +	audioreach_parse_cl_tokens(apm, sg, &tplg_w->priv);
> +
>  	cont = audioreach_parse_cont_tokens(apm, sg, &tplg_w->priv);
>  	if (IS_ERR(cont))
>  		return PTR_ERR(cont);

[Severity: Medium]
Does an error return after audioreach_parse_cl_tokens() leak the newly
allocated struct audioreach_control_link and its ID in
apm->control_links_idr?

If audioreach_parse_cont_tokens(), audioreach_parse_common_tokens() or
audioreach_get_module_priv_data() fails,
audioreach_widget_load_module_common() returns before setting
w->dobj.private = mod.  audioreach_widget_unload() bails out immediately
when dobj->private is NULL, so if no other widget in sg triggers subgraph
teardown (or if cont was already added to sg->container_list before the
failure, keeping sg->container_list non-empty), the control links on
sg->control_link_list are never removed from apm->control_links_idr or
freed.

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

  reply	other threads:[~2026-11-22 16:32 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-23 17:14 [RFC PATCH 00/23] ASoC: qcom: AudioReach Active speaker protection for WSA884x Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 01/23] ASoC: soc-core: allow default ch_maps on links with more than 8 DAIs Srinivas Kandagatla
2026-11-15 17:36   ` Mark Brown
2026-11-15 21:04     ` Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 02/23] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
2026-11-15 17:36   ` Mark Brown
2026-11-15 21:04     ` Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 03/23] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
2026-11-15 17:36   ` Mark Brown
2026-11-15 21:04     ` Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 04/23] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 05/23] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
2026-11-15 17:36   ` Mark Brown
2026-11-15 21:03     ` Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 06/23] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 07/23] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 08/23] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
2026-11-15 17:36   ` Mark Brown
2026-11-15 21:04     ` Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 09/23] ASoC: qcom: q6apm-dai: add S32_LE format support Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 10/23] ASoC: qcom: audioreach: support up to four speakers in VI feedback Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 11/23] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 12/23] ASoC: qcom: audioreach: make the speaker protection operation mode configurable Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 13/23] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 14/23] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 15/23] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 16/23] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 17/23] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 18/23] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 19/23] ASoC: qcom: audioreach: keep the last VI calibration result until the DSP reports Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 20/23] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
2026-11-15 17:36   ` Mark Brown
2026-11-15 21:03     ` Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 21/23] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
2026-10-23 17:14 ` [RFC PATCH 22/23] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
2026-10-28 13:38   ` Konrad Dybcio
2026-10-28 21:59     ` Srinivas Kandagatla
2026-10-29  8:17       ` Konrad Dybcio
2026-10-23 17:14 ` [RFC PATCH 23/23] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
2026-10-28 12:39 ` [RFC PATCH 00/23] ASoC: qcom: AudioReach Active speaker protection for WSA884x Mark Brown
2026-10-28 16:31 ` Fabian Renn-Giles
2026-10-28 21:56   ` Srinivas Kandagatla
2026-11-15 22:07     ` Srinivas Kandagatla
2026-11-22 16:14 ` [PATCH v2 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
2026-11-22 16:14 ` [PATCH v2 01/24] ASoC: soc-core: always allocate default ch_maps Srinivas Kandagatla
2026-11-22 16:31   ` sashiko-bot
2026-11-22 16:14 ` [PATCH v2 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
2026-11-22 16:14 ` [PATCH v2 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid Srinivas Kandagatla
2026-11-22 16:14 ` [PATCH v2 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
2026-11-22 16:38   ` sashiko-bot
2026-11-22 16:14 ` [PATCH v2 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell Srinivas Kandagatla
2026-11-22 16:14 ` [PATCH v2 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
2026-11-22 16:28   ` sashiko-bot
2026-11-22 16:14 ` [PATCH v2 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
2026-11-22 16:28   ` sashiko-bot
2026-11-22 16:14 ` [PATCH v2 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
2026-11-22 16:28   ` sashiko-bot
2026-11-22 16:14 ` [PATCH v2 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
2026-11-22 16:32   ` sashiko-bot [this message]
2026-11-22 16:14 ` [PATCH v2 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
2026-11-22 16:14 ` [PATCH v2 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support Srinivas Kandagatla
2026-11-22 16:14 ` [PATCH v2 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
2026-11-22 16:22   ` sashiko-bot
2026-11-22 16:14 ` [PATCH v2 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
2026-11-22 16:31   ` sashiko-bot
2026-11-22 16:14 ` [PATCH v2 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
2026-11-22 16:28   ` sashiko-bot
2026-11-22 16:14 ` [PATCH v2 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
2026-11-22 16:31   ` sashiko-bot
2026-11-22 16:14 ` [PATCH v2 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
2026-11-22 16:14 ` [PATCH v2 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
2026-11-22 16:14 ` [PATCH v2 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
2026-11-22 16:37   ` sashiko-bot
2026-11-22 16:14 ` [PATCH v2 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
2026-11-22 16:37   ` sashiko-bot
2026-11-22 16:14 ` [PATCH v2 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
2026-11-22 16:14 ` [PATCH v2 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
2026-11-22 16:14 ` [PATCH v2 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
2026-11-22 16:39   ` sashiko-bot
2026-11-22 16:14 ` [PATCH v2 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
2026-11-22 16:14 ` [PATCH v2 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
2026-11-22 16:37   ` 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-228107@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