From: Kery Qi <qikeyu2017@gmail.com>
To: lgirdwood@gmail.com
Cc: linux-kernel@vger.kernel.org, Kery Qi <qikeyu2017@gmail.com>
Subject: [PATCH] ASoC: rockchip: max98090: Fix reference leak in snd_rk_mc_probe
Date: Wed, 7 Jan 2026 23:22:13 +0800 [thread overview]
Message-ID: <20260107152213.1500-1-qikeyu2017@gmail.com> (raw)
The snd_rk_mc_probe() function calls of_parse_phandle() to acquire
device nodes for "rockchip,i2s-controller", "rockchip,audio-codec",
and "rockchip,hdmi-codec". These functions return device nodes with
incremented reference counts.
However, in several error paths (e.g., when rk_parse_headset_from_of(),
snd_soc_of_parse_card_name(), or devm_snd_soc_register_card() fails),
the function returns directly without releasing the acquired nodes,
leading to reference leaks.
This patch adds the missing of_node_put() calls in the error handling
paths. It also cleans up the of_node pointers in the dai_link structure
to prevent potential use-after-free issues.
Signed-off-by: Kery Qi <qikeyu2017@gmail.com>
---
sound/soc/rockchip/rockchip_max98090.c | 27 +++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/sound/soc/rockchip/rockchip_max98090.c b/sound/soc/rockchip/rockchip_max98090.c
index 075d0990a126..cd9305a5af72 100644
--- a/sound/soc/rockchip/rockchip_max98090.c
+++ b/sound/soc/rockchip/rockchip_max98090.c
@@ -414,6 +414,8 @@ static int snd_rk_mc_probe(struct platform_device *pdev)
card->dai_link[0].platforms->of_node = np_cpu;
} else {
dev_err(dev, "At least one of codecs should be specified\n");
+ if (np_cpu)
+ of_node_put(np_cpu);
return -EINVAL;
}
@@ -423,7 +425,7 @@ static int snd_rk_mc_probe(struct platform_device *pdev)
if (np_audio) {
ret = rk_parse_headset_from_of(dev, np);
if (ret)
- return ret;
+ goto err_put_nodes;
}
/* Parse card name. */
@@ -431,7 +433,7 @@ static int snd_rk_mc_probe(struct platform_device *pdev)
if (ret) {
dev_err(&pdev->dev,
"Soc parse card name failed %d\n", ret);
- return ret;
+ goto err_put_nodes;
}
/* register the soc card */
@@ -439,10 +441,29 @@ static int snd_rk_mc_probe(struct platform_device *pdev)
if (ret) {
dev_err(&pdev->dev,
"Soc register card failed %d\n", ret);
- return ret;
+ goto err_put_nodes;
}
return ret;
+
+err_put_nodes:
+ for (int i = 0; i < card->num_links; i++) {
+ if (card->dai_link[i].codecs->of_node)
+ card->dai_link[i].codecs->of_node = NULL;
+ if (card->dai_link[i].cpus->of_node)
+ card->dai_link[i].cpus->of_node = NULL;
+ if (card->dai_link[i].platforms->of_node)
+ card->dai_link[i].platforms->of_node = NULL;
+ }
+
+ if (np_audio)
+ of_node_put(np_audio);
+ if (np_hdmi)
+ of_node_put(np_hdmi);
+ if (np_cpu)
+ of_node_put(np_cpu);
+
+ return ret;
}
static const struct of_device_id rockchip_max98090_of_match[] = {
--
2.34.1
reply other threads:[~2026-01-07 15:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260107152213.1500-1-qikeyu2017@gmail.com \
--to=qikeyu2017@gmail.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®