[PATCH 04/14] ASoC: mediatek: mt8195: Fix timing system clock error handling

From: phucduc . bui

Date: Fri Sep 25 2026 - 00:55:48 EST


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

Check the return value of mt8195_afe_enable_clk() when enabling the
timing system clocks.

If enabling a clock fails, disable the clocks that were already
enabled and propagate the error to the caller. In
mt8195_afe_enable_main_clock(), return the error instead of continuing
with AFE clock enable.

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

diff --git a/sound/soc/mediatek/mt8195/mt8195-afe-clk.c b/sound/soc/mediatek/mt8195/mt8195-afe-clk.c
index 34c828fdea29..ef7a62fba6ec 100644
--- a/sound/soc/mediatek/mt8195/mt8195-afe-clk.c
+++ b/sound/soc/mediatek/mt8195/mt8195-afe-clk.c
@@ -662,7 +662,7 @@ static int mt8195_afe_disable_afe_on(struct mtk_base_afe *afe)
static int mt8195_afe_enable_timing_sys(struct mtk_base_afe *afe)
{
struct mt8195_afe_private *afe_priv = afe->platform_priv;
- int i;
+ int i, ret;
static const unsigned int clk_array[] = {
MT8195_CLK_AUD_A1SYS,
MT8195_CLK_AUD_A2SYS,
@@ -673,13 +673,22 @@ static int mt8195_afe_enable_timing_sys(struct mtk_base_afe *afe)
MT8195_TOP_CG_26M_TIMING,
};

- for (i = 0; i < ARRAY_SIZE(clk_array); i++)
- mt8195_afe_enable_clk(afe, afe_priv->clk[clk_array[i]]);
+ for (i = 0; i < ARRAY_SIZE(clk_array); i++) {
+ ret = mt8195_afe_enable_clk(afe, afe_priv->clk[clk_array[i]]);
+ if (ret)
+ goto err_disable_clk;
+ }

for (i = 0; i < ARRAY_SIZE(cg_array); i++)
mt8195_afe_enable_top_cg(afe, cg_array[i]);

return 0;
+
+err_disable_clk:
+ while (--i >= 0)
+ mt8195_afe_disable_clk(afe, afe_priv->clk[clk_array[i]]);
+
+ return ret;
}

static int mt8195_afe_disable_timing_sys(struct mtk_base_afe *afe)
@@ -707,7 +716,11 @@ static int mt8195_afe_disable_timing_sys(struct mtk_base_afe *afe)

int mt8195_afe_enable_main_clock(struct mtk_base_afe *afe)
{
- mt8195_afe_enable_timing_sys(afe);
+ int ret;
+
+ ret = mt8195_afe_enable_timing_sys(afe);
+ if (ret)
+ return ret;

mt8195_afe_enable_afe_on(afe);

--
2.43.0