From: Myeonghun Pak <mhun512@gmail.com>
To: Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, Ijae Kim <ae878000@gmail.com>,
Jiaxin Yu <jiaxin.yu@mediatek.com>
Subject: [PATCH v2 1/5] ASoC: mediatek: mt8186: Keep the AFE IRQ within its resource lifetime
Date: Thu, 12 Nov 2026 01:17:45 -0500 [thread overview]
Message-ID: <20261112011708-afe-v2-1-mhun512@gmail.com> (raw)
In-Reply-To: <20261112011708-afe-v2-0-mhun512@gmail.com>
The AFE IRQ handler uses afe->regmap, but its managed IRQ is requested
before the audiosys reset and before the regmap is initialized. Apart
from allowing an interrupt left pending by the firmware or a previous
kernel to dereference a NULL regmap, the reverse devres order releases
the regmap before the IRQ on probe failure and removal. The IRQ wake
setting enabled at probe is also never undone.
Request the IRQ after the reset, the regmap and the handler's other
inputs have been initialized, and keep the existing runtime PM error
cleanup for a failed request. Balance the IRQ wake setting on the
remaining probe error paths and in a new remove callback, which also
releases the IRQ before devres tears down the component and the regmap.
Save the IRQ number in the private state for that.
Found by a static analysis tool under development.
Fixes: 097e874ad3fc ("ASoC: mediatek: mt8186: add platform driver")
Co-developed-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
---
sound/soc/mediatek/mt8186/mt8186-afe-common.h | 1 +
sound/soc/mediatek/mt8186/mt8186-afe-pcm.c | 42 +++++++++++++------
2 files changed, 31 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 2f50f78a6f8c..134ff3947bff 100644
--- a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
+++ b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
@@ -2885,16 +2885,7 @@ static int mt8186_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, mt8186_afe_irq_handler,
- IRQF_TRIGGER_NONE,
- "Afe_ISR_Handle", (void *)afe);
- if (ret)
- return ret;
-
- 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);
@@ -2947,6 +2938,18 @@ 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)
+ 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,13 +2958,13 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
afe->dai_drivers,
afe->num_dai_drivers);
if (ret)
- 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;
@@ -2970,6 +2973,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);
@@ -2977,6 +2984,16 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
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", },
{},
@@ -2995,6 +3012,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);
--
2.43.0
next prev parent reply other threads:[~2026-11-12 6:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 6:17 [PATCH v2 0/5] ASoC: mediatek: fix AFE IRQ registration and removal ordering Myeonghun Pak
2026-11-12 6:17 ` Myeonghun Pak [this message]
2026-11-12 6:17 ` [PATCH v2 2/5] ASoC: mediatek: mt8189: Keep the AFE IRQ within its resource lifetime Myeonghun Pak
2026-11-12 6:17 ` [PATCH v2 3/5] ASoC: mediatek: mt8196: " Myeonghun Pak
2026-11-12 6:17 ` [PATCH v2 4/5] ASoC: mediatek: mt8195: " Myeonghun Pak
2026-11-12 6:17 ` [PATCH v2 5/5] ASoC: mediatek: mt8188: " Myeonghun Pak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261112011708-afe-v2-1-mhun512@gmail.com \
--to=mhun512@gmail.com \
--cc=ae878000@gmail.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=broonie@kernel.org \
--cc=jiaxin.yu@mediatek.com \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-sound@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®