[PATCH] ASoC: sun4i-codec: Fix OF node reference leaks for analog controls

Sushanto <[email protected]>
Newsgroups gmane.linux.kernel,gmane.linux.alsa.devel,gmane.linux.ports.arm.kernel
Message-ID <[email protected]>
The device node obtained from of_parse_phandle() for
"allwinner,codec-analog-controls" in sun8i_a23_codec_create_card(),
sun8i_h3_codec_create_card(), and sun8i_v3s_codec_create_card()
has its reference count incremented by of_parse_phandle().

However, the driver fails to drop this reference count when
sun4i_codec_create_link() fails, when snd_soc_register_card() fails
in sun4i_codec_probe(), or when the driver is removed in
sun4i_codec_remove().

Fix this by adding the missing of_node_put(aux_dev.dlc.of_node) calls
in these error paths and in sun4i_codec_remove().

Fixes: 08289086b0ab ("ASoC: sun4i-codec: Add support for A23 codec")
Signed-off-by: Sushanto <[email protected]>
---
 sound/soc/sunxi/sun4i-codec.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/sound/soc/sunxi/sun4i-codec.c b/sound/soc/sunxi/sun4i-codec.c
index 835dc3404..b10c2beac 100644
--- a/sound/soc/sunxi/sun4i-codec.c
+++ b/sound/soc/sunxi/sun4i-codec.c
@@ -1429,8 +1429,11 @@ static struct snd_soc_card *sun8i_a23_codec_create_card(struct device *dev)
 	}
 
 	card->dai_link = sun4i_codec_create_link(dev, &card->num_links);
-	if (!card->dai_link)
+	if (!card->dai_link) {
+		of_node_put(aux_dev.dlc.of_node);
+		aux_dev.dlc.of_node = NULL;
 		return ERR_PTR(-ENOMEM);
+	}
 
 	card->dev		= dev;
 	card->owner		= THIS_MODULE;
@@ -1468,8 +1471,11 @@ static struct snd_soc_card *sun8i_h3_codec_create_card(struct device *dev)
 	}
 
 	card->dai_link = sun4i_codec_create_link(dev, &card->num_links);
-	if (!card->dai_link)
+	if (!card->dai_link) {
+		of_node_put(aux_dev.dlc.of_node);
+		aux_dev.dlc.of_node = NULL;
 		return ERR_PTR(-ENOMEM);
+	}
 
 	card->dev		= dev;
 	card->owner		= THIS_MODULE;
@@ -1507,8 +1513,11 @@ static struct snd_soc_card *sun8i_v3s_codec_create_card(struct device *dev)
 	}
 
 	card->dai_link = sun4i_codec_create_link(dev, &card->num_links);
-	if (!card->dai_link)
+	if (!card->dai_link) {
+		of_node_put(aux_dev.dlc.of_node);
+		aux_dev.dlc.of_node = NULL;
 		return ERR_PTR(-ENOMEM);
+	}
 
 	card->dev		= dev;
 	card->owner		= THIS_MODULE;
@@ -1808,6 +1817,8 @@ static int sun4i_codec_probe(struct platform_device *pdev)
 	ret = snd_soc_register_card(card);
 	if (ret) {
 		dev_err_probe(&pdev->dev, ret, "Failed to register our card\n");
+		of_node_put(aux_dev.dlc.of_node);
+		aux_dev.dlc.of_node = NULL;
 		goto err_assert_reset;
 	}
 
@@ -1830,6 +1841,8 @@ static int sun4i_codec_remove(struct platform_device *pdev)
 	if (scodec->rst)
 		reset_control_assert(scodec->rst);
 	clk_disable_unprepare(scodec->clk_apb);
+	of_node_put(aux_dev.dlc.of_node);
+	aux_dev.dlc.of_node = NULL;
 
 	return 0;
 }
-- 
2.55.0.windows.4
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.