[PATCH 25/28] mfd: mt6397: Manage IRQ domain lifecycle with devres

From: Lee Jones

Date: Wed Oct 21 2026 - 08:24:25 EST


mt6397_irq_init() and mt6358_irq_init() create chip->irq_domain with
irq_domain_create_linear() before registering the parent interrupt via
devm_request_threaded_irq(). If devm_mfd_add_devices() fails in
mt6397_probe(), irq_domain_remove() is called before devres frees the
threaded IRQ and without disposing child IRQ mappings, allowing an
in-flight interrupt handler or late IRQ lookup to dereference the
removed domain. Conversely, when the driver is unbound, the IRQ
mappings and domain are never removed at all.

Register a devres action immediately after irq_domain_create_linear() to
dispose all mapped hardware interrupts and remove chip->irq_domain so
that the domain is torn down after child MFD devices and the managed IRQ
handler have been released on both probe failure and unbind.

Fixes: 6df8dd5c185b ("mfd: Add support for the MediaTek MT6397 PMIC")
Closes: https://sashiko.dev/#/bug/linux-b296fbe4-6e83-40c0-91c7-2c31e8d226d0
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/mfd/mt6358-irq.c | 17 ++++++++++++++++-
drivers/mfd/mt6397-core.c | 4 +---
drivers/mfd/mt6397-irq.c | 16 +++++++++++++++-
3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/drivers/mfd/mt6358-irq.c b/drivers/mfd/mt6358-irq.c
index 74cf20843044..c747cae909ea 100644
--- a/drivers/mfd/mt6358-irq.c
+++ b/drivers/mfd/mt6358-irq.c
@@ -224,6 +224,17 @@ static const struct irq_domain_ops mt6358_irq_domain_ops = {
.xlate = irq_domain_xlate_twocell,
};

+static void mt6358_irq_domain_remove(void *data)
+{
+ struct mt6397_chip *chip = data;
+ struct pmic_irq_data *irqd = chip->irq_data;
+
+ for (unsigned int hwirq = 0; hwirq < irqd->num_pmic_irqs; hwirq++)
+ irq_dispose_mapping(irq_find_mapping(chip->irq_domain, hwirq));
+
+ irq_domain_remove(chip->irq_domain);
+}
+
int mt6358_irq_init(struct mt6397_chip *chip)
{
int i, j, ret;
@@ -279,13 +290,17 @@ int mt6358_irq_init(struct mt6397_chip *chip)
return -ENODEV;
}

+ ret = devm_add_action_or_reset(chip->dev, mt6358_irq_domain_remove,
+ chip);
+ if (ret)
+ return ret;
+
ret = devm_request_threaded_irq(chip->dev, chip->irq, NULL,
mt6358_irq_handler, IRQF_ONESHOT,
mt6358_irq_chip.name, chip);
if (ret) {
dev_err(chip->dev, "Failed to register IRQ=%d, ret=%d\n",
chip->irq, ret);
- irq_domain_remove(chip->irq_domain);
return ret;
}

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 9ec951996588..e94e37cba249 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -395,10 +395,8 @@ static int mt6397_probe(struct platform_device *pdev)
ret = devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE,
pmic_core->cells, pmic_core->cell_size,
NULL, 0, pmic->irq_domain);
- if (ret) {
- irq_domain_remove(pmic->irq_domain);
+ if (ret)
dev_err(&pdev->dev, "failed to add child devices: %d\n", ret);
- }

return ret;
}
diff --git a/drivers/mfd/mt6397-irq.c b/drivers/mfd/mt6397-irq.c
index 5d2e5459f744..58645dbd8095 100644
--- a/drivers/mfd/mt6397-irq.c
+++ b/drivers/mfd/mt6397-irq.c
@@ -169,6 +169,16 @@ static int mt6397_irq_pm_notifier(struct notifier_block *notifier,
return NOTIFY_DONE;
}

+static void mt6397_irq_domain_remove(void *data)
+{
+ struct mt6397_chip *chip = data;
+
+ for (int hwirq = 0; hwirq < MT6397_IRQ_NR; hwirq++)
+ irq_dispose_mapping(irq_find_mapping(chip->irq_domain, hwirq));
+
+ irq_domain_remove(chip->irq_domain);
+}
+
int mt6397_irq_init(struct mt6397_chip *chip)
{
int ret;
@@ -223,13 +233,17 @@ int mt6397_irq_init(struct mt6397_chip *chip)
return -ENOMEM;
}

+ ret = devm_add_action_or_reset(chip->dev, mt6397_irq_domain_remove,
+ chip);
+ if (ret)
+ return ret;
+
ret = devm_request_threaded_irq(chip->dev, chip->irq, NULL,
mt6397_irq_thread, IRQF_ONESHOT,
"mt6397-pmic", chip);
if (ret) {
dev_err(chip->dev, "failed to register irq=%d; err: %d\n",
chip->irq, ret);
- irq_domain_remove(chip->irq_domain);
return ret;
}

--
2.56.0.218.g1ec904b173-goog