Skip to contentSkip to conversation

ASoC: omap-twl4030: Add missing of_node_put() in omap_twl4030_probe

PATCH New Kery Qi 1 participant 1 message Jan 7

Subsystems (4)
lore
Share & tools
lore

Kery Qi

author
#0 lore raw

PATCH 1/1 ASoC: omap-twl4030: Add missing of_node_put() in omap_twl4030_probe

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.

---
 sound/soc/ti/omap-twl4030.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
sound/soc/ti/omap-twl4030.c +14 -1
index 4d80f8a7a947..74ec05c915c6 100644
@@ -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;
 	}
 
Signature · 1 line
2.34.1