[PATCH] ASoC: audio-graph-card2: Fix use-after-free in audio_graph2_link_c2c()
From: Wentao Liang
Date: Thu Sep 17 2026 - 14:35:52 EST
of_graph_get_next_port() consumes the reference of its prev argument.
port0 is only borrowed from the caller's iterator, so the call drops a
reference the function does not own, and port0 is dereferenced again
afterwards. Pass an extra reference, as graph_count_c2c() does, so the
reference the callee consumes is the one taken here.
Fixes: 5f281c3e82b1 ("ASoC: audio-graph-card2: use __free(device_node) for device node")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
sound/soc/generic/audio-graph-card2.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/sound/soc/generic/audio-graph-card2.c b/sound/soc/generic/audio-graph-card2.c
index 0202ed0ee78e..268023d6f939 100644
--- a/sound/soc/generic/audio-graph-card2.c
+++ b/sound/soc/generic/audio-graph-card2.c
@@ -969,7 +969,8 @@ int audio_graph2_link_c2c(struct simple_util_priv *priv,
struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
struct device_node *port0 = lnk;
struct device_node *ports __free(device_node) = port_to_ports(port0);
- struct device_node *port1 __free(device_node) = of_graph_get_next_port(ports, port0);
+ struct device_node *port1 __free(device_node) =
+ of_graph_get_next_port(ports, of_node_get(port0));
u32 val = 0;
int ret = -EINVAL;
--
2.34.1