The omap_twl4030_probe() function calls of_parse_phandle() to acquire
device nodes for the "ti,mcbsp" and "ti,mcbsp-voice" properties.
of_parse_phandle() returns a device node with its reference count
incremented.
If snd_soc_of_parse_audio_routing() or devm_snd_soc_register_card()
fails, the function returns an error without releasing the acquired
device node, which leads to a reference leak.
This patch adds the missing of_node_put() in the error handling paths
to properly decrement the reference count. It also resets the of_node
pointers in the dai_links array to NULL to ensure a clean state upon
failure.
Signed-off-by: Kery Qi <qikeyu2017@gmail.com>
---
sound/soc/ti/omap-twl4030.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/sound/soc/ti/omap-twl4030.c b/sound/soc/ti/omap-twl4030.c
index 4d80f8a7a947..74ec05c915c6 100644
--- a/sound/soc/ti/omap-twl4030.c
+++ b/sound/soc/ti/omap-twl4030.c
@@ -285,8 +285,15 @@ static int omap_twl4030_probe(struct platform_device *pdev)
if (prop) {
ret = snd_soc_of_parse_audio_routing(card,
"ti,audio-routing");
- if (ret)
+ if (ret) {
+ omap_twl4030_dai_links[0].cpus->of_node = NULL;
+ omap_twl4030_dai_links[0].platforms->of_node = NULL;
+ omap_twl4030_dai_links[1].cpus->of_node = NULL;
+ omap_twl4030_dai_links[1].platforms->of_node = NULL;
+ if (dai_node)
+ of_node_put(dai_node);
return ret;
+ }
card->fully_routed = 1;
}
@@ -310,6 +317,12 @@ static int omap_twl4030_probe(struct platform_device *pdev)
if (ret) {
dev_err(&pdev->dev, "devm_snd_soc_register_card() failed: %d\n",
ret);
+ omap_twl4030_dai_links[0].cpus->of_node = NULL;
+ omap_twl4030_dai_links[0].platforms->of_node = NULL;
+ omap_twl4030_dai_links[1].cpus->of_node = NULL;
+ omap_twl4030_dai_links[1].platforms->of_node = NULL;
+ if (dai_node)
+ of_node_put(dai_node);
return ret;
}
--
2.34.1