[PATCH v2 3/5] ASoC: mediatek: mt8196: Keep the AFE IRQ within its resource lifetime
From: Myeonghun Pak
Date: Thu Nov 12 2026 - 01:19:14 EST
The managed AFE IRQ is requested before the regmap is allocated. The
handler can therefore run before its regmap exists, and devres releases
the regmap before freeing the IRQ. The remove callback also suspends the
AFE and disables its clocks before devres releases the IRQ.
Request the IRQ after initializing the regmap and before enabling MCU
IRQ routing. A failed request then takes the existing runtime PM unwind
without enabling that routing. Release the IRQ at the start of removal
before the explicit clock shutdown, using the IRQ number saved at probe.
The regmap's managed lifetime also encloses the IRQ on probe errors.
Found by a static analysis tool under development.
Fixes: 57513aabfe5b ("ASoC: mediatek: mt8196: add platform driver")
Co-developed-by: Ijae Kim <ae878000@xxxxxxxxx>
Signed-off-by: Ijae Kim <ae878000@xxxxxxxxx>
Signed-off-by: Myeonghun Pak <mhun512@xxxxxxxxx>
---
sound/soc/mediatek/mt8196/mt8196-afe-common.h | 1 +
sound/soc/mediatek/mt8196/mt8196-afe-pcm.c | 16 ++++++++++------
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/sound/soc/mediatek/mt8196/mt8196-afe-common.h b/sound/soc/mediatek/mt8196/mt8196-afe-common.h
index 4951a6f32abb..ce5d586721db 100644
--- a/sound/soc/mediatek/mt8196/mt8196-afe-common.h
+++ b/sound/soc/mediatek/mt8196/mt8196-afe-common.h
@@ -186,6 +186,7 @@ struct clk;
struct mtk_base_afe;
struct mt8196_afe_private {
+ int irq_id;
struct clk **clk;
/* dai */
void *dai_priv[MT8196_DAI_NUM];
diff --git a/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c b/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c
index f69ea22cfabb..dc462dd4235c 100644
--- a/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c
+++ b/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c
@@ -2403,12 +2403,7 @@ static int mt8196_afe_pcm_dev_probe(struct platform_device *pdev)
irq_id = platform_get_irq(pdev, 0);
if (irq_id < 0)
return irq_id;
-
- ret = devm_request_irq(dev, irq_id, mt8196_afe_irq_handler,
- IRQF_TRIGGER_NONE,
- "Afe_ISR_Handle", afe);
- if (ret)
- return ret;
+ afe_priv->irq_id = irq_id;
/* init sub_dais */
INIT_LIST_HEAD(&afe->sub_dais);
@@ -2463,6 +2458,12 @@ static int mt8196_afe_pcm_dev_probe(struct platform_device *pdev)
goto err_pm_put;
}
+ ret = devm_request_irq(dev, irq_id, mt8196_afe_irq_handler,
+ IRQF_TRIGGER_NONE,
+ "Afe_ISR_Handle", afe);
+ if (ret)
+ goto err_pm_put;
+
regmap_read(afe->regmap, AFE_IRQ_MCU_EN, &tmp_reg);
regmap_write(afe->regmap, AFE_IRQ_MCU_EN, 0xffffffff);
regmap_read(afe->regmap, AFE_IRQ_MCU_EN, &tmp_reg);
@@ -2490,8 +2491,11 @@ static int mt8196_afe_pcm_dev_probe(struct platform_device *pdev)
static void mt8196_afe_pcm_dev_remove(struct platform_device *pdev)
{
struct mtk_base_afe *afe = platform_get_drvdata(pdev);
+ struct mt8196_afe_private *afe_priv = afe->platform_priv;
struct device *dev = &pdev->dev;
+ devm_free_irq(dev, afe_priv->irq_id, afe);
+
if (!pm_runtime_status_suspended(dev))
mt8196_afe_runtime_suspend(dev);
--
2.43.0