Skip to contentSkip to conversation

ASoC: qcom: q6apm: initialize graph refcount before publishing

PATCH In review Ruoyu Wang 2 participants 2 messages Jun 17 – Jul 16

Subsystems (4)
lore
Share & tools
lore

Ruoyu Wang

author
#0 lore raw

PATCH 1/1 ASoC: qcom: q6apm: initialize graph refcount before publishing

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.

---
 sound/soc/qcom/qdsp6/q6apm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/qcom/qdsp6/q6apm.c +1 -2
index 2e5b25b8d00fd..1953e8ca8777b 100644
@@ -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);
 
 	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;
Signature · 1 line
2.51.0
#1 lore raw
Quoted 15 lines · Ruoyu Wang

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.

---
 sound/soc/qcom/qdsp6/q6apm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/qcom/qdsp6/q6apm.c +0 -0
index 2e5b25b8d00fd..1953e8ca8777b 100644

sound/soc/qcom/qdsp6/q6apm.c static struct audioreach_graph *q6apm_get_audioreach_graph(struct q6apm *apm, ui · line 69

Quoted 5 lines
sound/soc/qcom/qdsp6/q6apm.c +1 -0
@@ -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

Quoted 11 lines
sound/soc/qcom/qdsp6/q6apm.c +0 -2
 	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;