* [PATCH 0/3] ASoC: mediatek: fix AFE IRQ registration and removal ordering
@ 2026-10-11 22:22 Myeonghun Pak
2026-10-11 22:22 ` [PATCH 1/3] ASoC: mediatek: mt8186: Keep the AFE IRQ within its resource lifetime Myeonghun Pak
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Myeonghun Pak @ 2026-10-11 22:22 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-sound, linux-kernel, linux-arm-kernel, linux-mediatek, Ijae Kim
The AFE IRQ handlers access regmap and PCM state. Register each handler
after its inputs exist and release it before the final remove callback
or managed component teardown releases those inputs. The mt8186 patch
also balances IRQ wake settings on probe failure and removal.
Compile-tested with Clang 22.1.2, W=1 (arm64).
Base: 238650ef6c7c7cca08e032527329424c9fbd70e5
1. ASoC: mediatek: mt8186: Keep the AFE IRQ within its resource lifetime
2. ASoC: mediatek: mt8189: Keep the AFE IRQ within its resource lifetime
3. ASoC: mediatek: mt8196: Keep the AFE IRQ within its resource lifetime
Assisted-by: LLM
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] ASoC: mediatek: mt8186: Keep the AFE IRQ within its resource lifetime
2026-10-11 22:22 [PATCH 0/3] ASoC: mediatek: fix AFE IRQ registration and removal ordering Myeonghun Pak
@ 2026-10-11 22:22 ` Myeonghun Pak
2026-10-11 22:22 ` [PATCH 2/3] ASoC: mediatek: mt8189: " Myeonghun Pak
2026-10-11 22:22 ` [PATCH 3/3] ASoC: mediatek: mt8196: " Myeonghun Pak
2 siblings, 0 replies; 4+ messages in thread
From: Myeonghun Pak @ 2026-10-11 22:22 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-sound, linux-kernel, linux-arm-kernel, linux-mediatek, Ijae Kim
The AFE IRQ handler uses afe->regmap, but its managed IRQ is requested
before the regmap is initialized. Apart from allowing an early interrupt
to use an uninitialized regmap, the reverse devres order releases the
regmap before the IRQ on probe failure and removal.
Request the IRQ after the regmap and the handler's other inputs have been
initialized. Release and synchronize it explicitly on removal before the
managed ASoC components start tearing down their state. Balance the IRQ
wake setting on removal and on the remaining probe error paths, and keep
the existing runtime PM error cleanup for a failed IRQ request. Save the
IRQ number in the private state for final cleanup.
This issue was found by static analysis.
Fixes: 097e874ad3fc ("ASoC: mediatek: mt8186: add platform driver")
Assisted-by: LLM
Co-developed-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
---
Compile-tested with Clang 22.1.2, W=1 (arm64).
sound/soc/mediatek/mt8186/mt8186-afe-common.h | 1 +
sound/soc/mediatek/mt8186/mt8186-afe-pcm.c | 44 ++++++++++++++-----
2 files changed, 33 insertions(+), 12 deletions(-)
diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-common.h b/sound/soc/mediatek/mt8186/mt8186-afe-common.h
index d59258520995..d03e59ca7d65 100644
--- a/sound/soc/mediatek/mt8186/mt8186-afe-common.h
+++ b/sound/soc/mediatek/mt8186/mt8186-afe-common.h
@@ -139,6 +139,7 @@ struct mtk_base_irq_data;
struct clk;
struct mt8186_afe_private {
+ int irq_id;
struct clk **clk;
struct clk_lookup **lookup;
struct regmap *topckgen;
diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
index 44a521c3a610..ea61fa5fe372 100644
--- a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
+++ b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
@@ -2884,16 +2884,7 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
if (irq_id <= 0)
return dev_err_probe(dev, irq_id < 0 ? irq_id : -ENXIO,
"no irq found");
-
- ret = devm_request_irq(dev, irq_id, mt8186_afe_irq_handler,
- IRQF_TRIGGER_NONE,
- "Afe_ISR_Handle", (void *)afe);
- if (ret)
- return dev_err_probe(dev, ret, "could not request_irq for Afe_ISR_Handle\n");
-
- ret = enable_irq_wake(irq_id);
- if (ret < 0)
- return dev_err_probe(dev, ret, "enable_irq_wake %d\n", irq_id);
+ afe_priv->irq_id = irq_id;
/* init sub_dais */
INIT_LIST_HEAD(&afe->sub_dais);
@@ -2946,6 +2937,20 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
afe->runtime_resume = mt8186_afe_runtime_resume;
afe->runtime_suspend = mt8186_afe_runtime_suspend;
+ ret = devm_request_irq(dev, irq_id, mt8186_afe_irq_handler,
+ IRQF_TRIGGER_NONE,
+ "Afe_ISR_Handle", afe);
+ if (ret) {
+ dev_err_probe(dev, ret, "could not request_irq for Afe_ISR_Handle\n");
+ goto err_pm_disable;
+ }
+
+ ret = enable_irq_wake(irq_id);
+ if (ret < 0) {
+ dev_err_probe(dev, ret, "enable_irq_wake %d\n", irq_id);
+ goto err_free_irq;
+ }
+
/* register platform */
dev_dbg(dev, "%s(), devm_snd_soc_register_component\n", __func__);
@@ -2955,14 +2960,14 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
afe->num_dai_drivers);
if (ret) {
dev_err(dev, "err_dai_component\n");
- goto err_pm_disable;
+ goto err_disable_irq_wake;
}
ret = pm_runtime_put_sync(dev);
if (ret) {
pm_runtime_get_noresume(dev);
dev_err(dev, "failed to suspend device: %d\n", ret);
- goto err_pm_disable;
+ goto err_disable_irq_wake;
}
afe_priv->pm_runtime_bypass_reg_ctl = false;
@@ -2971,6 +2976,10 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
return 0;
+err_disable_irq_wake:
+ disable_irq_wake(irq_id);
+err_free_irq:
+ devm_free_irq(dev, irq_id, afe);
err_pm_disable:
pm_runtime_put_noidle(dev);
pm_runtime_set_suspended(dev);
@@ -2978,6 +2987,16 @@ err_pm_disable:
return ret;
}
+static void mt8186_afe_pcm_dev_remove(struct platform_device *pdev)
+{
+ struct mtk_base_afe *afe = platform_get_drvdata(pdev);
+ struct mt8186_afe_private *afe_priv = afe->platform_priv;
+ int irq_id = afe_priv->irq_id;
+
+ disable_irq_wake(irq_id);
+ devm_free_irq(&pdev->dev, irq_id, afe);
+}
+
static const struct of_device_id mt8186_afe_pcm_dt_match[] = {
{ .compatible = "mediatek,mt8186-sound", },
{},
@@ -2996,6 +3015,7 @@ static struct platform_driver mt8186_afe_pcm_driver = {
.pm = pm_ptr(&mt8186_afe_pm_ops),
},
.probe = mt8186_afe_pcm_dev_probe,
+ .remove = mt8186_afe_pcm_dev_remove,
};
module_platform_driver(mt8186_afe_pcm_driver);
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/3] ASoC: mediatek: mt8189: Keep the AFE IRQ within its resource lifetime
2026-10-11 22:22 [PATCH 0/3] ASoC: mediatek: fix AFE IRQ registration and removal ordering Myeonghun Pak
2026-10-11 22:22 ` [PATCH 1/3] ASoC: mediatek: mt8186: Keep the AFE IRQ within its resource lifetime Myeonghun Pak
@ 2026-10-11 22:22 ` Myeonghun Pak
2026-10-11 22:22 ` [PATCH 3/3] ASoC: mediatek: mt8196: " Myeonghun Pak
2 siblings, 0 replies; 4+ messages in thread
From: Myeonghun Pak @ 2026-10-11 22:22 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-sound, linux-kernel, linux-arm-kernel, linux-mediatek, Ijae Kim
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 joining 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.
This issue was found by static analysis.
Fixes: 7eb153585598 ("ASoC: mediatek: mt8189: add platform driver")
Assisted-by: LLM
Co-developed-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
---
Compile-tested with Clang 22.1.2, W=1 (arm64).
sound/soc/mediatek/mt8189/mt8189-afe-common.h | 1 +
sound/soc/mediatek/mt8189/mt8189-afe-pcm.c | 18 ++++++++++++------
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/sound/soc/mediatek/mt8189/mt8189-afe-common.h b/sound/soc/mediatek/mt8189/mt8189-afe-common.h
index 910d90d3d146..de715c92add5 100644
--- a/sound/soc/mediatek/mt8189/mt8189-afe-common.h
+++ b/sound/soc/mediatek/mt8189/mt8189-afe-common.h
@@ -202,6 +202,7 @@ enum {
struct clk;
struct mt8189_afe_private {
+ int irq_id;
struct clk **clk;
struct regmap *pmic_regmap;
diff --git a/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c b/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c
index 77cf2b604f6c..913c3b43fda8 100644
--- a/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c
+++ b/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c
@@ -2507,12 +2507,7 @@ static int mt8189_afe_pcm_dev_probe(struct platform_device *pdev)
irq_id = platform_get_irq(pdev, 0);
if (irq_id < 0)
return dev_err_probe(dev, irq_id, "no irq found");
-
- ret = devm_request_irq(dev, irq_id, mt8189_afe_irq_handler,
- IRQF_TRIGGER_NONE,
- "Afe_ISR_Handle", afe);
- if (ret)
- return dev_err_probe(dev, ret, "could not request_irq for Afe_ISR_Handle\n");
+ afe_priv->irq_id = irq_id;
/* init sub_dais */
INIT_LIST_HEAD(&afe->sub_dais);
@@ -2567,6 +2562,14 @@ static int mt8189_afe_pcm_dev_probe(struct platform_device *pdev)
goto err_pm_put;
}
+ ret = devm_request_irq(dev, irq_id, mt8189_afe_irq_handler,
+ IRQF_TRIGGER_NONE,
+ "Afe_ISR_Handle", afe);
+ if (ret) {
+ dev_err_probe(dev, ret, "could not request_irq for Afe_ISR_Handle\n");
+ 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);
@@ -2596,8 +2599,11 @@ err_pm_put:
static void mt8189_afe_pcm_dev_remove(struct platform_device *pdev)
{
struct mtk_base_afe *afe = platform_get_drvdata(pdev);
+ struct mt8189_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))
mt8189_afe_runtime_suspend(dev);
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/3] ASoC: mediatek: mt8196: Keep the AFE IRQ within its resource lifetime
2026-10-11 22:22 [PATCH 0/3] ASoC: mediatek: fix AFE IRQ registration and removal ordering Myeonghun Pak
2026-10-11 22:22 ` [PATCH 1/3] ASoC: mediatek: mt8186: Keep the AFE IRQ within its resource lifetime Myeonghun Pak
2026-10-11 22:22 ` [PATCH 2/3] ASoC: mediatek: mt8189: " Myeonghun Pak
@ 2026-10-11 22:22 ` Myeonghun Pak
2 siblings, 0 replies; 4+ messages in thread
From: Myeonghun Pak @ 2026-10-11 22:22 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-sound, linux-kernel, linux-arm-kernel, linux-mediatek, Ijae Kim
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 joining 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.
This issue was found by static analysis.
Fixes: 57513aabfe5b ("ASoC: mediatek: mt8196: add platform driver")
Assisted-by: LLM
Co-developed-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
---
Compile-tested with Clang 22.1.2, W=1 (arm64).
sound/soc/mediatek/mt8196/mt8196-afe-common.h | 1 +
sound/soc/mediatek/mt8196/mt8196-afe-pcm.c | 18 ++++++++++++------
2 files changed, 13 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 a1ae8322d8b6..39d9103bd5e7 100644
--- a/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c
+++ b/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c
@@ -2393,12 +2393,7 @@ static int mt8196_afe_pcm_dev_probe(struct platform_device *pdev)
irq_id = platform_get_irq(pdev, 0);
if (irq_id < 0)
return dev_err_probe(dev, irq_id, "no irq found");
-
- ret = devm_request_irq(dev, irq_id, mt8196_afe_irq_handler,
- IRQF_TRIGGER_NONE,
- "Afe_ISR_Handle", afe);
- if (ret)
- return dev_err_probe(dev, ret, "could not request_irq for Afe_ISR_Handle\n");
+ afe_priv->irq_id = irq_id;
/* init sub_dais */
INIT_LIST_HEAD(&afe->sub_dais);
@@ -2453,6 +2448,14 @@ 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) {
+ dev_err_probe(dev, ret, "could not request_irq for Afe_ISR_Handle\n");
+ 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);
@@ -2482,8 +2485,11 @@ err_pm_put:
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);
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-11 22:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-11 22:22 [PATCH 0/3] ASoC: mediatek: fix AFE IRQ registration and removal ordering Myeonghun Pak
2026-10-11 22:22 ` [PATCH 1/3] ASoC: mediatek: mt8186: Keep the AFE IRQ within its resource lifetime Myeonghun Pak
2026-10-11 22:22 ` [PATCH 2/3] ASoC: mediatek: mt8189: " Myeonghun Pak
2026-10-11 22:22 ` [PATCH 3/3] ASoC: mediatek: mt8196: " Myeonghun Pak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®