* [PATCH] ASoC: audio-graph-card2: Release multi-link ports references
@ 2026-11-19 7:58 Zhu Jun
2026-11-19 8:08 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Zhu Jun @ 2026-11-19 7:58 UTC (permalink / raw)
To: broonie; +Cc: lgirdwood, kuninori.morimoto.gx, linux-sound, linux-kernel,
Zhu Jun
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@cmss.chinamobile.com>
---
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.
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] ASoC: audio-graph-card2: Release multi-link ports references
2026-11-19 7:58 [PATCH] ASoC: audio-graph-card2: Release multi-link ports references Zhu Jun
@ 2026-11-19 8:08 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-19 8:08 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] ASoC: audio-graph-card2: double of_node_put() in
graph_link_init() [1]
--
commit bb6eb5c362dba929e29a53d648672a0c04801536
Author: Zhu Jun <zhujun2@cmss.chinamobile.com>
ASoC: audio-graph-card2: Release multi-link ports references
This commit uses __free(device_node) to release temporary device_node
references returned by port_to_ports() in graph_parse_node_multi_nm() and
graph_counter().
> diff --git a/sound/soc/generic/audio-graph-card2.c b/sound/soc/generic/audio-graph-card2.c
> index d2f32a3a5b28d..245a822c33586 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) {
[Severity: Critical]
This problem wasn't introduced by this patch, but in the multi-link node
handling in graph_link_init(), doesn't passing multi_cpu_port and
multi_codec_port to graph_get_next_multi_ep() cause a double of_node_put()
on port_cpu and port_codec [1]?
sound/soc/generic/audio-graph-card2.c:graph_link_init() {
struct device_node *port_cpu = ep_to_port(ep_cpu);
struct device_node *port_codec = ep_to_port(ep_codec);
...
if (graph_lnk_is_multi(port_cpu)) {
multi_cpu_port = port_cpu;
ep_cpu = graph_get_next_multi_ep(&multi_cpu_port, multi_cpu_port_idx++);
of_node_put(port_cpu);
port_cpu = ep_to_port(ep_cpu);
}
...
if (graph_lnk_is_multi(port_codec)) {
multi_codec_port = port_codec;
ep_codec = graph_get_next_multi_ep(&multi_codec_port, multi_codec_port_idx++);
of_node_put(port_codec);
port_codec = ep_to_port(ep_codec);
}
}
graph_get_next_multi_ep() calls of_node_put(*port) before replacing *port
with of_graph_get_port_by_id(ports, idx). Because port_cpu and port_codec
still hold the initial node pointers acquired by ep_to_port(), the
subsequent of_node_put(port_cpu) and of_node_put(port_codec) calls in
graph_link_init() drop those same references a second time, underflowing
the device_node reference counts and leading to use-after-free.
[1] https://sashiko.dev/#/bug/linux-cfb81a5c-4dcd-4040-99a5-4886fa74927e
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119075815.50155-1-zhujun2@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 8:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 7:58 [PATCH] ASoC: audio-graph-card2: Release multi-link ports references Zhu Jun
2026-11-19 8:08 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox