* [PATCH] ASoC: audio-graph-card2: Release multi-link ports references
@ 2026-11-19 7:58 Zhu Jun
2026-11-19 8:08 ` sashiko-bot
` (2 more replies)
0 siblings, 3 replies; 4+ 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] 4+ 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
2026-11-19 23:10 ` Kuninori Morimoto
2026-11-19 23:13 ` Mark Brown
2 siblings, 0 replies; 4+ 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] 4+ 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
@ 2026-11-19 23:10 ` Kuninori Morimoto
2026-11-19 23:13 ` Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Kuninori Morimoto @ 2026-11-19 23:10 UTC (permalink / raw)
To: Zhu Jun; +Cc: broonie, lgirdwood, linux-sound, linux-kernel
Hi
> 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>
> ---
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Thank you for your help !!
Best regards
---
Kuninori Morimoto
^ permalink raw reply [flat|nested] 4+ 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
2026-11-19 23:10 ` Kuninori Morimoto
@ 2026-11-19 23:13 ` Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2026-11-19 23:13 UTC (permalink / raw)
To: Zhu Jun; +Cc: lgirdwood, kuninori.morimoto.gx, linux-sound, linux-kernel
On Thu, 19 Nov 2026 15:58:15 +0800, Zhu Jun wrote:
> ASoC: audio-graph-card2: Release multi-link ports references
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.5
Thanks!
[1/1] ASoC: audio-graph-card2: Release multi-link ports references
https://git.kernel.org/broonie/sound/c/a0344bdd4636
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-20 12:19 UTC | newest]
Thread overview: 4+ 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
2026-11-19 23:10 ` Kuninori Morimoto
2026-11-19 23:13 ` Mark Brown
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.