imx_card_parse_of() takes references on the CPU and codec device nodes
with snd_soc_of_get_dlc() and snd_soc_of_get_dai_link_codecs() and
stores them in the link's component arrays. The driver has no remove
callback and the ASoC core does not drop these references when the card
is unregistered, so unbinding the platform device or unloading the
module leaks one device node reference per CPU and codec.

Add a remove callback that releases the references of all links, in the
same way as other machine drivers do.

Fixes: aa736700f42f ("ASoC: imx-card: Add imx-card machine driver")
Cc: [email protected]
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <[email protected]>
---
 sound/soc/fsl/imx-card.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/sound/soc/fsl/imx-card.c b/sound/soc/fsl/imx-card.c
index e3cb1438e837..242c5eaff6f9 100644
--- a/sound/soc/fsl/imx-card.c
+++ b/sound/soc/fsl/imx-card.c
@@ -927,6 +927,18 @@ static int imx_card_probe(struct platform_device *pdev)
        return 0;
 }
 
+static void imx_card_remove(struct platform_device *pdev)
+{
+       struct snd_soc_card *card = dev_get_drvdata(&pdev->dev);
+       struct snd_soc_dai_link *link;
+       int i;
+
+       for_each_card_prelinks(card, i, link) {
+               snd_soc_of_put_dai_link_cpus(link);
+               snd_soc_of_put_dai_link_codecs(link);
+       }
+}
+
 static const struct of_device_id imx_card_dt_ids[] = {
        { .compatible = "fsl,imx-audio-card", },
        { },
@@ -940,6 +952,7 @@ static struct platform_driver imx_card_driver = {
                .of_match_table = imx_card_dt_ids,
        },
        .probe = imx_card_probe,
+       .remove = imx_card_remove,
 };
 module_platform_driver(imx_card_driver);
 
-- 
2.34.1


Reply via email to