* [PATCH v2 00/27] mfd: Assorted resource lifetime, teardown, and error-handling fixes
@ 2026-10-27 9:30 Lee Jones
2026-10-27 9:30 ` [PATCH v2 24/27] mfd: mt6397: Manage IRQ domain lifecycle with devres Lee Jones
2026-10-27 9:30 ` [PATCH v2 25/27] mfd: mt6397: Unregister PM notifier on probe failure and unbind Lee Jones
0 siblings, 2 replies; 5+ messages in thread
From: Lee Jones @ 2026-10-27 9:30 UTC (permalink / raw)
To: lee, Matthias Brugger, AngeloGioacchino Del Regno, linux-kernel,
linux-arm-kernel, linux-mediatek
Cc: Aaro Koskinen, Andi Shyti, Andreas Kemnade, Andy Shevchenko,
AnilKumar Ch, Arnd Bergmann, Binbin Zhou, Brent Casavant,
Chong Qiao, Corey Minyard, David Lechner, Dmitry Torokhov,
Felipe Balbi, Gyungoh Yoo, Heikki Krogerus, Hsin-Hsiung Wang,
Huacai Chen, Jarkko Nikula, Jonathan Cameron, Joshua Kinard,
Kai Svahn, Kevin Hilman, Kumar Sanghvi, Linus Walleij,
linux-crypto, linux-i2c, linux-iio, linux-input, linux-omap,
Mattias Nilsson, Mattias Wallin, Matti Vaittinen, mfd,
Mika Westerberg, Milo Kim, Ming Yu, Nuno Sá,
Pantelis Antoniou, Pat Gefre, Paul Burton, Peter Ujfalusi,
Qunqin Zhao, Rabin Vincent, Rachna Patil, Roger Quadros,
Samuel Ortiz, Sascha Hauer, Sebastian Andrzej Siewior, Shi Hao,
Srinidhi Kasagar, Stanislaw Skowronek, Stephen Warren,
Sundar Iyer, syed khasim, Thomas Bogendoerfer, Thomas Richard,
Tony Lindgren, Yinggang Gu
These issues were reported by Sashiko.
This series addresses a collection of resource lifetime, teardown
ordering, error-handling, and bounds-checking bugs across several MFD
drivers.
v1 => v2:
- Collected Acked-by, Reviewed-by, and Tested-by tags from the list
- Dropped "mfd: cgbc: Zero-initialise version buffer in
cgbc_get_version()" in favour of Thomas Richard's upcoming central
cgbc_command() validation series
- Restored Fixes: tags (without Cc: stable@vger.kernel.org) on the four
non-Stable MFD cell stack-pointer clean-ups (ls2kbmc, bd96801,
ti_am335x_tscadc, and db8500-prcmu)
Cc: Aaro Koskinen <aaro.koskinen@iki.fi>
Cc: Andi Shyti <andi.shyti@kernel.org>
Cc: Andreas Kemnade <andreas@kemnade.info>
Cc: Andy Shevchenko <andy@kernel.org>
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Cc: AnilKumar Ch <anilkumar@ti.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Binbin Zhou <zhoubinbin@loongson.cn>
Cc: Brent Casavant <bcasavan@sgi.com>
Cc: Chong Qiao <qiaochong@loongson.cn>
Cc: Corey Minyard <corey@minyard.net>
Cc: David Lechner <dlechner@baylibre.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Felipe Balbi <balbi@ti.com>
Cc: Gyungoh Yoo <jack.yoo@maxim-ic.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Joshua Kinard <linux@kumba.dev>
Cc: Kai Svahn <kai.svahn@nokia.com>
Cc: Kevin Hilman <khilman@baylibre.com>
Cc: Kumar Sanghvi <kumar.sanghvi@stericsson.com>
Cc: Linus Walleij <linusw@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-crypto@vger.kernel.org
Cc: linux-i2c@vger.kernel.org
Cc: linux-iio@vger.kernel.org
Cc: linux-input@vger.kernel.org
Cc: linux-mediatek@lists.infradead.org
Cc: linux-omap@vger.kernel.org
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: Mattias Nilsson <mattias.i.nilsson@stericsson.com>
Cc: Mattias Wallin <mattias.wallin@stericsson.com>
Cc: Matti Vaittinen <mazziesaccount@gmail.com>
Cc: mfd@lists.linux.dev
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Milo Kim <woogyom.kim@gmail.com>
Cc: Ming Yu <tmyu0@nuvoton.com>
Cc: "Nuno Sá" <nuno.sa@analog.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Pat Gefre <pfg@sgi.com>
Cc: Paul Burton <paulburton@kernel.org>
Cc: Peter Ujfalusi <peter.ujfalusi@ti.com>
Cc: Qunqin Zhao <zhaoqunqin@loongson.cn>
Cc: Rabin Vincent <rabin.vincent@stericsson.com>
Cc: Rachna Patil <rachna@ti.com>
Cc: Roger Quadros <rogerq@kernel.org>
Cc: Samuel Ortiz <sameo@linux.intel.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Shi Hao <i.shihao.999@gmail.com>
Cc: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com>
Cc: Stanislaw Skowronek <skylark@unaligned.org>
Cc: Stephen Warren <swarren@nvidia.com>
Cc: Sundar Iyer <sundar.iyer@stericsson.com>
Cc: syed khasim <x0khasim@ti.com>
Cc: Thomas Bogendoerfer <tbogendoerfer@suse.de>
Cc: Thomas Richard <thomas.richard@bootlin.com>
Cc: Tony Lindgren <tony@atomide.com>
Cc: Yinggang Gu <guyinggang@loongson.cn>
Lee Jones (27):
mfd: nct6694: Allocate USB DMA buffers with kzalloc_obj()
mfd: ls2kbmc: Unregister GPIO GSI via devm_add_action_or_reset()
mfd: ls2kbmc: Cancel reset work on teardown via devm_work_autocancel()
mfd: ls2kbmc: Allocate simplefb platform_data on the heap
mfd: bd96801: Allocate watchdog IRQ resource on the heap
mfd: ti_am335x_tscadc: Retrieve parent driver data via
dev_get_drvdata()
mfd: db8500-prcmu: Make AB8500 cell and IRQ resource static
mfd: nct6694: Do not resubmit interrupt URB on endpoint stall (-EPIPE)
mfd: ioc3: Request parent IRQ via request_irq() and free before domain
removal
mfd: intel-lpss: Remove registered MFD child devices on probe failure
mfd: max8907: Manage power-off handler via
devm_register_sys_off_handler()
mfd: twl-core: Clear pm_power_off callback in twl_remove()
mfd: twl-core: Clear twl_priv pointer on teardown and probe failure
mfd: loongson-se: Check return value of dma_set_mask_and_coherent()
mfd: loongson-se: Zero-initialise controller command structures
mfd: loongson-se: Reinitialise completions and wait uninterruptibly
for commands
mfd: loongson-se: Zero-allocate driver data and initialise engine
completions in probe
mfd: loongson-se: Prevent out-of-bounds engine access in
se_irq_handler()
mfd: loongson-se: Stop controller and mask interrupts on teardown and
shutdown
mfd: loongson-se: Validate engine ID, DMA buffer size, and IRQ
registration
mfd: abx500-core: Unregister device ops on devm release
mfd: ab8500-core: Register sysfs attribute groups via
devm_device_add_group()
mfd: tps65217: Manage IRQ domain teardown via devres
mfd: mt6397: Manage IRQ domain lifecycle with devres
mfd: mt6397: Unregister PM notifier on probe failure and unbind
i2c: cgbc: Propagate hardware errors when polling read status
mfd: ti_am335x_tscadc: Remove redundant ti_tscadc_dev_get() helper
drivers/i2c/busses/i2c-cgbc.c | 27 ++++--
drivers/iio/adc/ti_am335x_adc.c | 2 +-
drivers/input/touchscreen/ti_am335x_tsc.c | 2 +-
drivers/mfd/ab8500-core.c | 11 +--
drivers/mfd/abx500-core.c | 29 +++---
drivers/mfd/db8500-prcmu.c | 8 +-
drivers/mfd/intel-lpss.c | 1 +
drivers/mfd/ioc3.c | 32 ++++---
drivers/mfd/loongson-se.c | 110 +++++++++++++++++-----
drivers/mfd/ls2k-bmc-core.c | 27 ++++--
drivers/mfd/max8907.c | 28 ++++--
drivers/mfd/mt6358-irq.c | 17 +++-
drivers/mfd/mt6397-core.c | 4 +-
drivers/mfd/mt6397-irq.c | 31 +++++-
drivers/mfd/nct6694.c | 23 +++--
drivers/mfd/rohm-bd96801.c | 11 ++-
drivers/mfd/ti_am335x_tscadc.c | 7 +-
drivers/mfd/tps65217.c | 40 ++++----
drivers/mfd/twl-core.c | 45 +++++----
include/linux/mfd/loongson-se.h | 8 +-
include/linux/mfd/ti_am335x_tscadc.h | 7 --
21 files changed, 326 insertions(+), 144 deletions(-)
--
2.56.0.307.g5fe7bd680c-goog
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 24/27] mfd: mt6397: Manage IRQ domain lifecycle with devres
2026-10-27 9:30 [PATCH v2 00/27] mfd: Assorted resource lifetime, teardown, and error-handling fixes Lee Jones
@ 2026-10-27 9:30 ` Lee Jones
2026-10-28 3:45 ` Chen-Yu Tsai
2026-10-27 9:30 ` [PATCH v2 25/27] mfd: mt6397: Unregister PM notifier on probe failure and unbind Lee Jones
1 sibling, 1 reply; 5+ messages in thread
From: Lee Jones @ 2026-10-27 9:30 UTC (permalink / raw)
To: lee, Matthias Brugger, AngeloGioacchino Del Regno, Sascha Hauer,
mfd, linux-kernel, linux-arm-kernel, linux-mediatek
Cc: stable
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@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
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.307.g5fe7bd680c-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 25/27] mfd: mt6397: Unregister PM notifier on probe failure and unbind
2026-10-27 9:30 [PATCH v2 00/27] mfd: Assorted resource lifetime, teardown, and error-handling fixes Lee Jones
2026-10-27 9:30 ` [PATCH v2 24/27] mfd: mt6397: Manage IRQ domain lifecycle with devres Lee Jones
@ 2026-10-27 9:30 ` Lee Jones
2026-10-28 4:15 ` Chen-Yu Tsai
1 sibling, 1 reply; 5+ messages in thread
From: Lee Jones @ 2026-10-27 9:30 UTC (permalink / raw)
To: lee, Matthias Brugger, AngeloGioacchino Del Regno,
Hsin-Hsiung Wang, mfd, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: stable
mt6397_irq_init() registers a power management notifier block embedded
in the devres-managed struct mt6397_chip via register_pm_notifier(),
but never unregisters it if mt6397_probe() later fails or when the
driver is unbound. Once devres frees struct mt6397_chip, the dangling
notifier block corrupts the global PM notifier chain and causes a
use-after-free on subsequent suspend or resume transitions.
Check the return value of register_pm_notifier() and register a devres
action to unregister the PM notifier on probe failure or device unbind.
Fixes: 4e2e7cfec13a ("mfd: mt6397: Modify suspend/resume behavior")
Closes: https://sashiko.dev/#/bug/linux-edb62fbc-213a-49a2-be55-c002e234e554
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/mfd/mt6397-irq.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/mfd/mt6397-irq.c b/drivers/mfd/mt6397-irq.c
index 58645dbd8095..bc7ca22d6f17 100644
--- a/drivers/mfd/mt6397-irq.c
+++ b/drivers/mfd/mt6397-irq.c
@@ -179,6 +179,13 @@ static void mt6397_irq_domain_remove(void *data)
irq_domain_remove(chip->irq_domain);
}
+static void mt6397_unregister_pm_notifier(void *data)
+{
+ struct mt6397_chip *chip = data;
+
+ unregister_pm_notifier(&chip->pm_nb);
+}
+
int mt6397_irq_init(struct mt6397_chip *chip)
{
int ret;
@@ -247,6 +254,10 @@ int mt6397_irq_init(struct mt6397_chip *chip)
return ret;
}
- register_pm_notifier(&chip->pm_nb);
- return 0;
+ ret = register_pm_notifier(&chip->pm_nb);
+ if (ret)
+ return ret;
+
+ return devm_add_action_or_reset(chip->dev,
+ mt6397_unregister_pm_notifier, chip);
}
--
2.56.0.307.g5fe7bd680c-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 24/27] mfd: mt6397: Manage IRQ domain lifecycle with devres
2026-10-27 9:30 ` [PATCH v2 24/27] mfd: mt6397: Manage IRQ domain lifecycle with devres Lee Jones
@ 2026-10-28 3:45 ` Chen-Yu Tsai
0 siblings, 0 replies; 5+ messages in thread
From: Chen-Yu Tsai @ 2026-10-28 3:45 UTC (permalink / raw)
To: Lee Jones
Cc: Matthias Brugger, AngeloGioacchino Del Regno, Sascha Hauer, mfd,
linux-kernel, linux-arm-kernel, linux-mediatek, stable
On Tue, Oct 27, 2026 at 6:38 PM Lee Jones <lee@kernel.org> wrote:
>
> 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@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 25/27] mfd: mt6397: Unregister PM notifier on probe failure and unbind
2026-10-27 9:30 ` [PATCH v2 25/27] mfd: mt6397: Unregister PM notifier on probe failure and unbind Lee Jones
@ 2026-10-28 4:15 ` Chen-Yu Tsai
0 siblings, 0 replies; 5+ messages in thread
From: Chen-Yu Tsai @ 2026-10-28 4:15 UTC (permalink / raw)
To: Lee Jones
Cc: Matthias Brugger, AngeloGioacchino Del Regno, Hsin-Hsiung Wang,
mfd, linux-kernel, linux-arm-kernel, linux-mediatek, stable
On Tue, Oct 27, 2026 at 6:38 PM Lee Jones <lee@kernel.org> wrote:
>
> mt6397_irq_init() registers a power management notifier block embedded
> in the devres-managed struct mt6397_chip via register_pm_notifier(),
> but never unregisters it if mt6397_probe() later fails or when the
> driver is unbound. Once devres frees struct mt6397_chip, the dangling
> notifier block corrupts the global PM notifier chain and causes a
> use-after-free on subsequent suspend or resume transitions.
>
> Check the return value of register_pm_notifier() and register a devres
> action to unregister the PM notifier on probe failure or device unbind.
>
> Fixes: 4e2e7cfec13a ("mfd: mt6397: Modify suspend/resume behavior")
> Closes: https://sashiko.dev/#/bug/linux-edb62fbc-213a-49a2-be55-c002e234e554
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Though in practice, if one hits this then they have bigger problems.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-10-28 4:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-27 9:30 [PATCH v2 00/27] mfd: Assorted resource lifetime, teardown, and error-handling fixes Lee Jones
2026-10-27 9:30 ` [PATCH v2 24/27] mfd: mt6397: Manage IRQ domain lifecycle with devres Lee Jones
2026-10-28 3:45 ` Chen-Yu Tsai
2026-10-27 9:30 ` [PATCH v2 25/27] mfd: mt6397: Unregister PM notifier on probe failure and unbind Lee Jones
2026-10-28 4:15 ` Chen-Yu Tsai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox