[PATCH 3/5] ASoC: rockchip: rk3399_gru_sound: fix codec node reference leak

From: shao.mingyin

Date: Sat Nov 07 2026 - 03:11:49 EST


From: Shao Mingyin <shao.mingyin@xxxxxxxxxx>

rockchip_sound_of_parse_dais() takes a reference on np_codec with
of_parse_phandle() on every iteration. When the codec is disabled or
does not match a known codec, the loop continues without dropping that
reference, so the node is never released.

Put the node on both skip paths. When the codec matches, the reference
is still transferred to the DAI link, so that path is unchanged.

Fixes: 0d52954ffe80 ("ASoC: rockchip: Parse dai links from dts")
Signed-off-by: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
---
Tested on 7.3.0-next-20261030 (QEMU/TCG arm64 guest) with a synthetic
device tree on the QEMU "virt" machine; no RK3399 board or audio
controller is needed to reach the parse loop. A test-only hook, applied
to both kernels, compares the reference count of a disabled codec node
referenced by rockchip,codec with an identical unreferenced control
node:

unpatched patched
codec refs 4, control 3 (delta 1) codec refs 3, control 3 (delta 0)

diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c
index d4a0daabfb42..d18688b74ae9 100644
--- a/sound/soc/rockchip/rk3399_gru_sound.c
+++ b/sound/soc/rockchip/rk3399_gru_sound.c
@@ -540,12 +540,16 @@ static int rockchip_sound_of_parse_dais(struct device *dev,
if (!np_codec)
break;

- if (!of_device_is_available(np_codec))
+ if (!of_device_is_available(np_codec)) {
+ of_node_put(np_codec);
continue;
+ }

index = rockchip_sound_codec_node_match(np_codec);
- if (index < 0)
+ if (index < 0) {
+ of_node_put(np_codec);
continue;
+ }

switch (index) {
case DAILINK_CDNDP: