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

Message ID 20260825141035.784-1-seditorofficial@gmail.com (mailing list archive)
State New
Headers
Series ASoC: sun4i-codec: Fix OF node reference leaks for analog controls |

Commit Message

Sushanto Aug. 25, 2026, 2:10 p.m. UTC
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 <seditorofficial@gmail.com>
---
 sound/soc/sunxi/sun4i-codec.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
  

Comments

Mark Brown Aug. 26, 2026, 3:19 p.m. UTC | #1
On Tue, Aug 25, 2026 at 08:10:35PM +0600, Sushanto wrote:
> 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().

This doesn't apply against current code, please check and resend.
  

Patch

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;
 }