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=1796130564; b=cr9OSH3WDKA9EJ2KjXwD3QsrZv2ofX0909t3Gz+jd+fbu+ISlG0Vf0UhuDZKHSO9s4dC Z0gIPyfe2IwF1a4BhuVNToP6euM/8EHuDPGt8IN/PHfbQdgQztfkCKh4JrhXwECo20oCH jxhNoJu/3beT3vZlvMghreynXej4q5Sg9bOQmzwHh0GwHXzhox65gvSLdi2FxKcYX8mtD LeOiwfVqOCD7A7T0ozu0TtR3YLjuAe1xp0wCd3wUKTkZfIm6+iDwYv3xItht9tgHnqIQu +fEAAmvLqUjjQV5iKZT/tvtq5JD+Xfmasz1mqu/d372uNRUkWnGExQRvTEyqXD2ByQA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796130564; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=5hw5xabyn2WEmk2o0womvBuIDQo8k5NRO4pHiBIrxpw=; b=KFfpJsjmIDumzFQg++p2TlzAtwaCGFgKjoAnbmjwzo68bIp3Ox3o6xHVei09tM7nQxtd V8HqfNXn9gvkRnSUE/E16vgDHiy7nadWsp5xRtDi1XX2GBLJSk4gVqSiG3FGY/Bib0RWF eIIxhHZtHi4W/iRvxv4smwOu3m04uXPaQtUzO2ZNNDKLi6HyYW18E9VGrZpuj9Xiyhn3f zPYq4dBrWIDCbeKQBJDyQYi2kPfdT4WybMDs0093P9DKonUYBqJamNcZCYyM8m/ZTh/fn jK1sIby4F0lY8NnSWm6JGrxN30bwegQCAVy8sllVAVcZzqTMJPgKzB1SZtngRfi4pPQ== 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=CqNNMrvp; 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 4D7FB606A31A; Tue, 1 Dec 2026 13:09:24 +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=CqNNMrvp Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC9781F0089F; Tue, 1 Dec 2026 13:09:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796130564; bh=5hw5xabyn2WEmk2o0womvBuIDQo8k5NRO4pHiBIrxpw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=CqNNMrvp1fcLMjDSBVU3zL5VjAQlAGS2I5SorW77bx96xvrOtxE58yH7hYQprwKDq me31A5o5FZzD5abgf+1g3hVjFv90CeHT274sn1bFMmvdX688ecSvvy2scIHfK2t/ko 8pzYsY+b62CiquO2KXBEO1bdp501Uu4PCHy/hy6ORIQcp/dx/UULkw46cnkbQWLpWj JUl5b+GrzOPLOFwSVCreTzGqvGN18djPNkMLYI39rsylh2AEjqsewoLCSdMgOZp9DB 8Kp2mZ6VMdWFG8UbZNEKZEpw53Bfuazn83rN0vsn6zQqtk4zeKGKKXn7yOir6ZNqam XRA5NGz5fCGiA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 09/24] ASoC: qcom: audioreach: add control link support to graphs 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: <20261201124753.196748-10-srinivas.kandagatla@oss.qualcomm.com> References: <20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com> <20261201124753.196748-10-srinivas.kandagatla@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 13:09:22 +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: audioreach: control link stride and param_size mismatch - [Medium] ASoC: qcom: audioreach: underflow and infinite loop in audioreach_parse_cl_tokens() - [Medium] ASoC: qcom: audioreach: control link leak on widget load failure -- commit 81c62eeed7c8f4aa7eb81d4000c3ddba0ee624c7 Author: Srinivas Kandagatla ASoC: qcom: audioreach: add control link support to graphs This commit parses control link tokens from the AudioReach topology into a per-subgraph list and appends deduplicated control link configurations to the APM_CMD_GRAPH_OPEN packet. > diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/aud= ioreach.c > index 5b5289bf6d139..f66d3ff68a441 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 { > =20 > #define APM_MOD_CONN_PSIZE(p, n) ALIGN(struct_size(p, conn_obj, n), 8) > =20 > +/* 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) [ ... ] > @@ -426,6 +449,47 @@ static void audioreach_populate_graph(struct q6apm *= apm, > =20 > apm_populate_sub_graph_config(sg_cfg, sg); > =20 > + list_for_each_entry(clink, &sg->control_link_list, node) { > + bool dup =3D false; > + int k; > + > + /* Both subgraphs usually declare the link, send it once */ > + for (k =3D 0; k < nlink; k++) { > + struct apm_control_link_obj *o =3D &cl_data->link_obj[k]; > + > + if ((o->peer1_mod_inst_id =3D=3D clink->peer1_mod_inst_id && > + o->peer2_mod_inst_id =3D=3D clink->peer2_mod_inst_id) || > + (o->peer1_mod_inst_id =3D=3D clink->peer2_mod_inst_id && > + o->peer2_mod_inst_id =3D=3D clink->peer1_mod_inst_id)) { > + dup =3D true; > + break; > + } > + } > + if (dup) > + continue; > + > + clink_obj =3D &cl_data->link_obj[nlink++]; > + clink_obj->peer1_mod_inst_id =3D clink->peer1_mod_inst_id; > + clink_obj->peer1_mod_port_id =3D clink->peer1_mod_port_id; > + clink_obj->peer2_mod_inst_id =3D clink->peer2_mod_inst_id; > + clink_obj->peer2_mod_port_id =3D clink->peer2_mod_port_id; > + clink_obj->intent_data.prop_id =3D APM_MODULE_PROP_ID_CTRL_LINK_INTEN= T_LIST; > + clink_obj->num_props =3D 1; > + clink_obj->num_intents =3D 0; > + > + /* Pack the intents that are set into a dense list */ > + for (j =3D 0; j < MAX_INTENTS; j++) { > + if (clink->intent[j]) > + clink_obj->intent_id_list[clink_obj->num_intents++] =3D > + clink->intent[j]; > + } > + > + /* The list length itself is part of the property payload */ > + clink_obj->intent_data.prop_size =3D > + sizeof(clink_obj->num_intents) + > + clink_obj->num_intents * sizeof(clink_obj->intent_id_list[0]); > + } [ ... ] > @@ -461,12 +525,16 @@ static void audioreach_populate_graph(struct q6apm = *apm, > ncontainer++; > } > } > + > + /* The dedupe above may have packed fewer links */ > + cl_data->num_ctrl_link_cfg =3D nlink; > } [ ... ] > @@ -568,6 +639,15 @@ void *audioreach_alloc_graph_pkt(struct q6apm *apm, > params.mod_conn_list_data->num_connections =3D num_connections; > p +=3D mc_sz; > =20 > + /* Control Links */ > + params.mod_control_links_data =3D p; > + param_data =3D ¶ms.mod_control_links_data->param_data; > + param_data->module_instance_id =3D APM_MODULE_INSTANCE_ID; > + param_data->param_id =3D APM_PARAM_ID_MODULE_CTRL_LINK_CFG; > + param_data->param_size =3D cl_sz - APM_MODULE_PARAM_DATA_SIZE; > + params.mod_control_links_data->num_ctrl_link_cfg =3D num_control_links; > + p +=3D cl_sz; > + > audioreach_populate_graph(apm, info, ¶ms, sg_list, num_sub_graphs); > =20 > return pkt; [Severity: High] Does indexing cl_data->link_obj[] with a fixed MAX_INTENTS array stride mat= ch the variable-length intent_data.prop_size expected by the DSP? struct apm_control_link_obj declares intent_id_list[MAX_INTENTS], giving ea= ch link_obj entry a fixed 48-byte stride, whereas intent_data.prop_size only counts the non-zero clink_obj->num_intents packed into intent_id_list[]. When a control link has fewer than MAX_INTENTS intents and multiple links a= re present, the DSP advances past intent_data by prop_size bytes and reads the trailing unused zero slots of intent_id_list[] as the header of the next control link. Also, audioreach_alloc_graph_pkt() sets param_data->param_size from the pre-deduplication num_control_links count (and always emits the APM_PARAM_ID_MODULE_CTRL_LINK_CFG section even when num_control_links is 0), while audioreach_populate_graph() updates cl_data->num_ctrl_link_cfg =3D nl= ink without updating cl_data->param_data.param_size, leaving param_size and num_ctrl_link_cfg inconsistent whenever duplicate links are skipped. > diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topol= ogy.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; > } > =20 > +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 =3D cl_array->valu= e; > + int tkn_count =3D 0; > + > + while (tkn_count <=3D (le32_to_cpu(cl_array->num_elems) - 1)) { [ ... ] > +static void audioreach_parse_cl_tokens(struct q6apm *apm, struct audiore= ach_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 =3D false; > + > + for (sz =3D 0; sz < le32_to_cpu(private->size);) { > + cl_array =3D (struct snd_soc_tplg_vendor_array *)((u8 *)private->array= + sz); > + cl_elem =3D cl_array->value; > + sz =3D sz + le32_to_cpu(cl_array->size); > + tkn_count =3D 0; > + > + /* Module config blobs are not token tuples, stop here */ > + if (le32_to_cpu(cl_array->type) =3D=3D SND_SOC_AR_TPLG_MODULE_CFG_TYPE) > + break; > + > + while (tkn_count <=3D (le32_to_cpu(cl_array->num_elems) - 1)) { > + if (le32_to_cpu(cl_elem->token) =3D=3D AR_TKN_U32_CONTROL_LINK_IID) { > + link_id =3D le32_to_cpu(cl_elem->value); > + link =3D 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 in audioreach_parse_cl_tokens() and audioreach_parse_control_link_tokens()? le32_to_cpu() returns an unsigned 32-bit value, so when cl_array->num_elems is 0 the subtraction wraps to U32_MAX, promoting tkn_count to unsigned and reading past the end of cl_array->value. In addition, if cl_array->size is 0 on a non-module-cfg array, sz never advances and the outer loop in audioreach_parse_cl_tokens() spins forever before audioreach_get_module_priv_data() is reached. Errors returned by audioreach_tplg_alloc_control_link() are also silently ignored instead of being propagated to audioreach_widget_load_module_common(). > @@ -617,6 +742,8 @@ static int audioreach_widget_load_module_common(struc= t snd_soc_component *compon > if (IS_ERR(sg)) > return PTR_ERR(sg); > =20 > + audioreach_parse_cl_tokens(apm, sg, &tplg_w->priv); > + > cont =3D audioreach_parse_cont_tokens(apm, sg, &tplg_w->priv); > if (IS_ERR(cont)) > return PTR_ERR(cont); [Severity: Medium] Does an error after audioreach_parse_cl_tokens() in audioreach_widget_load_module_common() leak the allocated audioreach_control_link objects and their IDs 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_comm= on() returns before setting w->dobj.private =3D mod. audioreach_widget_unload() returns immediately when dobj->private is NULL, so any control links added = to sg->control_link_list and apm->control_links_idr for that widget are not cleaned up if the subgraph has no other loaded containers or if a failed container remains on sg->container_list. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201124753.1967= 48-1-srinivas.kandagatla@oss.qualcomm.com?part=3D9