[PATCH] ASoC: audio-graph-card2: Release multi-link ports references

From: Zhu Jun

Date: Thu Nov 19 2026 - 02:58:24 EST


port_to_ports() returns a referenced ports node. graph_counter() drops
the pointer after counting the ports, while graph_parse_node_multi_nm()
compares it with the expected codec ports node and discards it. The
references remain held after card parsing, including across reprobes.

Use the existing device_node cleanup pattern at both call sites, so
the temporary references are released when their scopes end.

Fixes: e2de6808df4a ("ASoC: audio-graph-card2: add CPU:Codec = N:M support")
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
---
sound/soc/generic/audio-graph-card2.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/soc/generic/audio-graph-card2.c b/sound/soc/generic/audio-graph-card2.c
index 4708bbba1a3c..210c789d4b7c 100644
--- a/sound/soc/generic/audio-graph-card2.c
+++ b/sound/soc/generic/audio-graph-card2.c
@@ -559,9 +559,10 @@ static int graph_parse_node_multi_nm(struct simple_util_priv *priv,

struct device_node *mcodec_ep_n __free(device_node) = of_graph_get_remote_endpoint(mcpu_ep_n);
struct device_node *mcodec_port __free(device_node) = ep_to_port(mcodec_ep_n);
+ struct device_node *ports __free(device_node) = port_to_ports(mcodec_port);

ret = -EINVAL;
- if (mcodec_ports != port_to_ports(mcodec_port))
+ if (mcodec_ports != ports)
break;

for_each_of_graph_port(mcodec_ports, mcodec_port_i) {
@@ -1117,7 +1118,7 @@ static int graph_counter(struct device_node *lnk)
* ignore first lnk part
*/
if (graph_lnk_is_multi(lnk)) {
- struct device_node *ports = port_to_ports(lnk);
+ struct device_node *ports __free(device_node) = port_to_ports(lnk);

/*
* CPU/Codec = N:M case has many endpoints.