Re: [PATCH] ASoC: qcom: q6apm: initialize graph refcount before publishing

From: Srinivas Kandagatla

Date: Thu Jul 16 2026 - 17:22:23 EST




On 6/17/26 7:21 PM, Ruoyu Wang wrote:
> q6apm_get_audioreach_graph() inserts a newly allocated graph into
> graph_idr before initializing its refcount. Another caller looking up the
> same graph id can find the graph and call kref_get() before kref_init().
> Initialize the refcount before publishing the graph in the IDR.
>
> Signed-off-by: Ruoyu Wang <ruoyuw560@xxxxxxxxx>
> ---
> sound/soc/qcom/qdsp6/q6apm.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c
> index 2e5b25b8d00fd..1953e8ca8777b 100644
> --- a/sound/soc/qcom/qdsp6/q6apm.c
> +++ b/sound/soc/qcom/qdsp6/q6apm.c
> @@ -65,6 +65,7 @@ static struct audioreach_graph *q6apm_get_audioreach_graph(struct q6apm *apm, ui
> graph->apm = apm;
> graph->info = info;
> graph->id = graph_id;
> + kref_init(&graph->refcount);
>

this is going to break the error handing further down the code.

--srini
> graph->graph = audioreach_alloc_graph_pkt(apm, info);
> if (IS_ERR(graph->graph)) {
> @@ -85,8 +86,6 @@ static struct audioreach_graph *q6apm_get_audioreach_graph(struct q6apm *apm, ui
> }
> mutex_unlock(&apm->lock);
>
> - kref_init(&graph->refcount);
> -
> q6apm_send_cmd_sync(apm, graph->graph, 0);
>
> return graph;