[PATCH 06/14] ASoC: mediatek: mt8195: Fix FE startup error handling

From: phucduc . bui

Date: Fri Sep 25 2026 - 00:51:13 EST


From: bui duc phuc <phucduc.bui@xxxxxxxxx>

Check and propagate errors from paired memif clock preparation and
PCM hardware constraints during FE startup.

Unprepare the paired memif clocks and shut down the FE when a later
startup step fails to avoid leaving resources enabled on error.

Fixes: 6746cc858259 ("ASoC: mediatek: mt8195: add platform driver")
Signed-off-by: bui duc phuc <phucduc.bui@xxxxxxxxx>
---
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c | 40 +++++++++++++++-------
1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/sound/soc/mediatek/mt8195/mt8195-afe-pcm.c b/sound/soc/mediatek/mt8195/mt8195-afe-pcm.c
index 1d3e01e2c3e7..5e76625915a5 100644
--- a/sound/soc/mediatek/mt8195/mt8195-afe-pcm.c
+++ b/sound/soc/mediatek/mt8195/mt8195-afe-pcm.c
@@ -364,24 +364,38 @@ static int mt8195_afe_fe_startup(struct snd_pcm_substream *substream,
int id = snd_soc_rtd_to_cpu(rtd, 0)->id;
int ret = 0;

- mt8195_afe_paired_memif_clk_prepare(substream, dai, 1);
+ ret = mt8195_afe_paired_memif_clk_prepare(substream, dai, 1);
+ if (ret)
+ return ret;

ret = mtk_afe_fe_startup(substream, dai);
+ if (ret)
+ goto err_clk_unprepare;

- snd_pcm_hw_constraint_step(runtime, 0,
- SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
- MT8195_MEMIF_BUFFER_BYTES_ALIGN);
+ ret = snd_pcm_hw_constraint_step(runtime, 0,
+ SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
+ MT8195_MEMIF_BUFFER_BYTES_ALIGN);
+ if (ret)
+ goto err_fe_shutdow;

- if (id != MT8195_AFE_MEMIF_DL7)
- goto out;
+ if (id == MT8195_AFE_MEMIF_DL7) {
+ ret = snd_pcm_hw_constraint_minmax(runtime,
+ SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+ 1,
+ MT8195_MEMIF_DL7_MAX_PERIOD_SIZE);
+ if (ret < 0) {
+ dev_dbg(afe->dev, "hw_constraint_minmax failed\n");
+ goto err_fe_shutdow;
+ }
+ }
+
+ return 0;
+
+err_fe_shutdow:
+ mtk_afe_fe_shutdown(substream, dai);
+err_clk_unprepare:
+ mt8195_afe_paired_memif_clk_prepare(substream, dai, 0);

- ret = snd_pcm_hw_constraint_minmax(runtime,
- SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
- 1,
- MT8195_MEMIF_DL7_MAX_PERIOD_SIZE);
- if (ret < 0)
- dev_dbg(afe->dev, "hw_constraint_minmax failed\n");
-out:
return ret;
}

--
2.43.0