[PATCH 1/4] ASoC: mediatek: common: Keep codec references until the card is bound

From: Michał Kopeć

Date: Sat Oct 03 2026 - 15:47:34 EST


mtk_soundcard_common_probe() drops the codec references parsed from the
devicetree right after devm_snd_soc_register_card() returns. When a
component is still missing, snd_soc_bind_card() queues the card for a
later rebind and registration still returns success, so the card is not
instantiated yet. The rebind reuses the same dai_link array, but with the
codec references released both the codec name and of_node are unset, so
it fails the dai link sanity check and the sound card never appears.

Release the references right away only when the card was instantiated
or registration failed. Otherwise keep them for the rebind and release
them when the device is unbound.

Fixes: bce93a162505 ("ASoC: mediatek: Add common machine soundcard driver probe mechanism")
Signed-off-by: Michał Kopeć <michal@nozomi.space>
---
.../mediatek/common/mtk-soundcard-driver.c | 23 +++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/sound/soc/mediatek/common/mtk-soundcard-driver.c b/sound/soc/mediatek/common/mtk-soundcard-driver.c
index 2d39ff23f8540..4bb98412feb11 100644
--- a/sound/soc/mediatek/common/mtk-soundcard-driver.c
+++ b/sound/soc/mediatek/common/mtk-soundcard-driver.c
@@ -129,6 +129,11 @@ void clean_card_reference(struct snd_soc_card *card)
}
EXPORT_SYMBOL_GPL(clean_card_reference);

+static void mtk_soundcard_put_card_reference(void *data)
+{
+ clean_card_reference(data);
+}
+
int mtk_soundcard_startup(struct snd_pcm_substream *substream,
enum mtk_pcm_constraint_type ctype)
{
@@ -325,8 +330,22 @@ int mtk_soundcard_common_probe(struct platform_device *pdev)

ret = devm_snd_soc_register_card(&pdev->dev, card);

- if (!needs_legacy_probe)
- clean_card_reference(card);
+ /*
+ * When a component is still missing, snd_soc_bind_card() queues the
+ * card for a later rebind and returns success, so the card is not
+ * instantiated yet. That rebind reuses this same dai_link array, so
+ * the codec references parsed from the devicetree must be kept until
+ * the device is unbound: dropping them leaves both name and of_node
+ * unset and the rebind fails the dai link sanity check instead.
+ */
+ if (!needs_legacy_probe) {
+ if (ret || snd_soc_card_is_instantiated(card))
+ clean_card_reference(card);
+ else
+ ret = devm_add_action_or_reset(&pdev->dev,
+ mtk_soundcard_put_card_reference,
+ card);
+ }

if (ret) {
dev_err_probe(&pdev->dev, ret, "Cannot register card\n");
--
2.55.0