mt2701_cs42448_machine_probe() takes three of_parse_phandle() references, for "mediatek,platform", "mediatek,audio-codec" and "mediatek,audio-codec-bt-mrg", and stores them in the DAI links. Later failures in routing, GPIO lookup or card registration return with those references still held, and the success path never drops them either. Register a devres action for each parsed node. It runs when probe fails and, on unbind, only after snd_soc_unregister_card(). Fixes: 1f458d53f76c ("ASoC: mediatek: Add mt2701-cs42448 driver and config option.") Cc: stable@vger.kernel.org Signed-off-by: Yuwei Chen <2522445001@qq.com> --- sound/soc/mediatek/mt2701/mt2701-cs42448.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sound/soc/mediatek/mt2701/mt2701-cs42448.c b/sound/soc/mediatek/mt2701/mt2701-cs42448.c index ff7a1bac848c..2490e764107b 100644 --- a/sound/soc/mediatek/mt2701/mt2701-cs42448.c +++ b/sound/soc/mediatek/mt2701/mt2701-cs42448.c @@ -313,6 +313,11 @@ static struct snd_soc_card mt2701_cs42448_soc_card = { .num_dapm_widgets = ARRAY_SIZE(mt2701_cs42448_asoc_card_dapm_widgets), }; +static void mt2701_cs42448_of_node_put(void *np) +{ + of_node_put(np); +} + static int mt2701_cs42448_machine_probe(struct platform_device *pdev) { struct snd_soc_card *card = &mt2701_cs42448_soc_card; @@ -333,6 +338,10 @@ static int mt2701_cs42448_machine_probe(struct platform_device *pdev) dev_err(dev, "Property 'platform' missing or invalid\n"); return -EINVAL; } + ret = devm_add_action_or_reset(dev, mt2701_cs42448_of_node_put, + platform_node); + if (ret) + return ret; for_each_card_prelinks(card, i, dai_link) { if (dai_link->platforms->name) continue; @@ -348,6 +357,10 @@ static int mt2701_cs42448_machine_probe(struct platform_device *pdev) "Property 'audio-codec' missing or invalid\n"); return -EINVAL; } + ret = devm_add_action_or_reset(dev, mt2701_cs42448_of_node_put, + codec_node); + if (ret) + return ret; for_each_card_prelinks(card, i, dai_link) { if (dai_link->codecs->name) continue; @@ -361,6 +374,10 @@ static int mt2701_cs42448_machine_probe(struct platform_device *pdev) "Property 'audio-codec-bt-mrg' missing or invalid\n"); return -EINVAL; } + ret = devm_add_action_or_reset(dev, mt2701_cs42448_of_node_put, + codec_node_bt_mrg); + if (ret) + return ret; mt2701_cs42448_dai_links[DAI_LINK_BE_MRG_BT].codecs->of_node = codec_node_bt_mrg; base-commit: 3dbdc13bd4b313b3d94c0f719378a4641a39db46 -- 2.53.0.windows.2