mfd: Fix potential cleanup ordering and lifetime bugs
Subsystems (7)
cover mfd: Fix potential cleanup ordering and lifetime bugs
Remove child devices while their IRQ providers are still available, and avoid deleting a managed IRQ chip twice.
The changed driver objects were build-tested. No hardware testing was performed.
Guangshuo Li (6):
mfd: da9055: Fix potential use-after-free during removal
mfd: atc260x: Fix potential use-after-free on probe failure
mfd: palmas: Fix potential IRQ action leaks on removal
mfd: stmpe: Fix potential use-after-free during removal
mfd: stmfx: Fix potential IRQ action leaks on removal
mfd: wm8994: Fix potential use-after-free during removal
drivers/mfd/atc260x-core.c | 4 +--- drivers/mfd/da9055-core.c | 2 +- drivers/mfd/palmas.c | 3 +++ drivers/mfd/stmfx.c | 8 +++++--- drivers/mfd/stmpe.c | 4 ++-- drivers/mfd/wm8994-core.c | 7 +++++-- 6 files changed, 17 insertions(+), 11 deletions(-)
base-commit: d89e1d186ec9271bf78e62771779e9fc03bf0fc3
PATCH 1/6 mfd: da9055: Fix potential use-after-free during removal
da9055_device_exit() deletes the IRQ chip before removing its children. The onkey driver's remove callback then uses the freed IRQ-chip data to look up its interrupt number. Remove the children before deleting the IRQ chip.
This issue was found by our static analysis tool under development.
---
Build-tested the changed object with x86_64 defconfig plus COMPILE_TEST and the driver dependencies (W=1).
No runtime or fault-injection testing was performed.
drivers/mfd/da9055-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/da9055-core.c +1 -1
@@ -393,8 +393,8 @@ int da9055_device_init(struct da9055 *da9055)void da9055_device_exit (struct da9055 *da9055) { -regmap_del_irq_chip (da9055->chip_irq, da9055->irq_data);mfd_remove_devices (da9055->dev); +regmap_del_irq_chip (da9055->chip_irq, da9055->irq_data); }MODULE_DESCRIPTION ("Core support for the DA9055 PMIC" );
[email protected]
AI reviewRe: [PATCH 1/6] mfd: da9055: Fix potential use-after-free during removal
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
da9055_device_exit()deletes the IRQ chip before removing its children. The onkey driver's remove callback then uses the freed IRQ-chip data to look up its interrupt number. Remove the children before deleting the IRQ chip.This issue was found by our static analysis tool under development.
Fixes 2896434cf272 ("mfd: DA9055 core driver")Assisted-by OpenAI:gpt-6-astraSigned-off-by Guangshuo Li <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/6 mfd: atc260x: Fix potential use-after-free on probe failure
In reply to Guangshuo LiThe IRQ chip is device-managed, but the child registration failure path also deletes it explicitly. Subsequent devres cleanup can then access the freed IRQ-chip data. Let devres perform the IRQ-chip teardown.
This issue was found by our static analysis tool under development.
---
Build-tested the changed object with x86_64 defconfig plus COMPILE_TEST and the driver dependencies (W=1).
No runtime or fault-injection testing was performed.
drivers/mfd/atc260x-core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mfd/atc260x-core.c +1 -3
@@ -292,10 +292,8 @@ int atc260x_device_probe(struct atc260x *atc260x) ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , atc260x->cells, atc260x->nr_cells,NULL ,0 ,regmap_irq_get_domain (atc260x->irq_data)); -if (ret) { +if (ret)dev_err (dev,"Failed to add child devices: %d\n" , ret); -regmap_del_irq_chip (atc260x->irq, atc260x->irq_data); - }return ret; }
[email protected]
AI reviewRe: [PATCH 2/6] mfd: atc260x: Fix potential use-after-free on probe failure
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
The IRQ chip is device-managed, but the child registration failure path also deletes it explicitly. Subsequent devres cleanup can then access the freed IRQ-chip data. Let devres perform the IRQ-chip teardown.
This issue was found by our static analysis tool under development.
Fixes f7cb7fe34db9 ("mfd: Add MFD driver for ATC260x PMICs")Assisted-by OpenAI:gpt-6-astraSigned-off-by Guangshuo Li <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH 2/6] mfd: atc260x: Fix potential use-after-free on probe failure
In reply to Guangshuo LiQuoted 10 lines · Guangshuo Li
The IRQ chip is device-managed, but the child registration failure path also deletes it explicitly. Subsequent devres cleanup can then access the freed IRQ-chip data. Let devres perform the IRQ-chip teardown.
This issue was found by our static analysis tool under development.
Fixes f7cb7fe34db9 ("mfd: Add MFD driver for ATC260x PMICs")Assisted-by OpenAI:gpt-6-astraSigned-off-by Guangshuo Li <[email protected]>
PATCH 3/6 mfd: palmas: Fix potential IRQ action leaks on removal
In reply to Guangshuo LiThe remove callback deletes the IRQ chip before managed OF children are removed. Their later free_irq() calls cannot find the disposed IRQ descriptors, potentially leaking interrupt actions. Depopulate the children before deleting the IRQ chip and auxiliary I2C clients.
This issue was found by our static analysis tool under development.
---
Build-tested the changed object with x86_64 defconfig plus COMPILE_TEST and the driver dependencies (W=1).
No runtime or fault-injection testing was performed.
drivers/mfd/palmas.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mfd/palmas.c +3 -0
@@ -677,6 +677,9 @@ static void palmas_i2c_remove(struct i2c_client *i2c)struct palmas *palmas =i2c_get_clientdata (i2c);int i; +if (i2c->dev.of_node) +devm_of_platform_depopulate (&i2c->dev); +regmap_del_irq_chip (palmas->irq, palmas->irq_data);for (i =1 ; i <PALMAS_NUM_CLIENTS ; i++) {
[email protected]
AI reviewRe: [PATCH 3/6] mfd: palmas: Fix potential IRQ action leaks on removal
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
The remove callback deletes the IRQ chip before managed OF children are removed. Their later
free_irq()calls cannot find the disposed IRQ descriptors, potentially leaking interrupt actions. Depopulate the children before deleting the IRQ chip and auxiliary I2C clients.This issue was found by our static analysis tool under development.
Fixes 124e9deb1c40 ("mfd: palmas: Use devm_of_platform_populate()")Assisted-by OpenAI:gpt-6-astraSigned-off-by Guangshuo Li <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Lee Jones
maintainerRe: [PATCH 3/6] mfd: palmas: Fix potential IRQ action leaks on removal
In reply to Guangshuo LiQuoted 24 lines · Guangshuo Li
The remove callback deletes the IRQ chip before managed OF children are removed. Their later
free_irq()calls cannot find the disposed IRQ descriptors, potentially leaking interrupt actions. Depopulate the children before deleting the IRQ chip and auxiliary I2C clients.This issue was found by our static analysis tool under development.
Fixes 124e9deb1c40 ("mfd: palmas: Use devm_of_platform_populate()")Assisted-by OpenAI:gpt-6-astraSigned-off-by Guangshuo Li <[email protected]>---
Build-tested the changed object withx86_64defconfig plusCOMPILE_TESTand the driver dependencies (W=1).
No runtime or fault-injection testing was performed.drivers/mfd/palmas.c | 3 +++ 1 file changed, 3 insertions(+)drivers/mfd/palmas.c +0
-0
drivers/mfd/palmas.c static void palmas_i2c_remove(struct i2c_client *i2c) · line 681
Quoted 5 lines
drivers/mfd/palmas.c +2
-0@@ -677,6 +677,9 @@ static void palmas_i2c_remove(struct i2c_client *i2c)struct palmas *palmas =i2c_get_clientdata (i2c);int i; +if (i2c->dev.of_node) +devm_of_platform_depopulate (&i2c->dev);
I think it would be nice to devm_* regmap_add_irq_chip() instead.
If you also convert the auxiliary I2C clients and 'pm_power_off' teardown to devm, you could drop palmas_i2c_remove() altogether.
Quoted 4 lines
drivers/mfd/palmas.c +1
-0+regmap_del_irq_chip (palmas->irq, palmas->irq_data);for (i =1 ; i <PALMAS_NUM_CLIENTS ; i++) {
Signature · 1 line
Lee Jones
Re:Re: [PATCH 3/6] mfd: palmas: Fix potential IRQ action leaks on removal
Hi Lee,
Thanks for the review.
From: Lee Jones <[email protected]>
Date: 2026-11-13 21:09:18
To: Guangshuo Li <[email protected]>
Cc: [email protected],Aaro Koskinen <[email protected]>,Andreas Kemnade <[email protected]>,Kevin Hilman <[email protected]>,Roger Quadros <[email protected]>,Tony Lindgren <[email protected]>,[email protected],[email protected],[email protected]
Quoted 33 lines · Guangshuo Li
Quoted 25 lines
The remove callback deletes the IRQ chip before managed OF children are removed. Their later
free_irq()calls cannot find the disposed IRQ descriptors, potentially leaking interrupt actions. Depopulate the children before deleting the IRQ chip and auxiliary I2C clients.This issue was found by our static analysis tool under development.
Fixes 124e9deb1c40 ("mfd: palmas: Use devm_of_platform_populate()")Assisted-by OpenAI:gpt-6-astraSigned-off-by Guangshuo Li <[email protected]>---
Build-tested the changed object withx86_64defconfig plusCOMPILE_TESTand the driver dependencies (W=1).
No runtime or fault-injection testing was performed.drivers/mfd/palmas.c | 3 +++ 1 file changed, 3 insertions(+)drivers/mfd/palmas.c +0
-0drivers/mfd/palmas.c static void palmas_i2c_remove(struct i2c_client *i2c) · line 681
Quoted 5 lines
drivers/mfd/palmas.c +2
-0@@ -677,6 +677,9 @@ static void palmas_i2c_remove(struct i2c_client *i2c)struct palmas *palmas =i2c_get_clientdata (i2c);int i; +if (i2c->dev.of_node) +devm_of_platform_depopulate (&i2c->dev);I think it would be nice to devm_*
regmap_add_irq_chip()instead.
Quoted 11 lines
If you also convert the auxiliary I2C clients and '
pm_power_off' teardown to devm, you could droppalmas_i2c_remove()altogether.Quoted 4 lines
drivers/mfd/palmas.c +1
-0+regmap_del_irq_chip (palmas->irq, palmas->irq_data);for (i =1 ; i <PALMAS_NUM_CLIENTS ; i++) {Signature · 1 line
Lee Jones
The IRQ chip is registered before devm_of_platform_populate(). With devm_regmap_add_irq_chip(), the children would be removed while their IRQ mappings are still valid.
If the auxiliary I2C clients and the power-off handler use managed cleanup too, I think palmas_i2c_remove() can go away. Is that what you had in mind? If so, I'll send a v2 for palmas along those lines.
Thanks,
Guangshuo
Lee Jones
maintainerRe: Re: [PATCH 3/6] mfd: palmas: Fix potential IRQ action leaks on removal
Quoted 10 lines · 李广硕
Hi Lee,
Thanks for the review.
From: Lee Jones <[email protected]>
Date: 2026-11-13 21:09:18
To: Guangshuo Li <[email protected]>
Cc: [email protected],Aaro Koskinen <[email protected]>,Andreas Kemnade <[email protected]>,Kevin Hilman <[email protected]>,Roger Quadros <[email protected]>,Tony Lindgren <[email protected]>,[email protected],[email protected],[email protected]
Subject: Re: [PATCH 3/6] mfd: palmas: Fix potential IRQ action leaks on removal>On Sat, 31 Oct 2026, Guangshuo Li wrote:
Please reconfigure your mailer. These headers shouldn't be in the body.
Quoted 44 lines
Quoted 32 lines
Quoted 24 lines
The remove callback deletes the IRQ chip before managed OF children are removed. Their later
free_irq()calls cannot find the disposed IRQ descriptors, potentially leaking interrupt actions. Depopulate the children before deleting the IRQ chip and auxiliary I2C clients.This issue was found by our static analysis tool under development.
Fixes 124e9deb1c40 ("mfd: palmas: Use devm_of_platform_populate()")Assisted-by OpenAI:gpt-6-astraSigned-off-by Guangshuo Li <[email protected]>---
Build-tested the changed object withx86_64defconfig plusCOMPILE_TESTand the driver dependencies (W=1).
No runtime or fault-injection testing was performed.drivers/mfd/palmas.c | 3 +++ 1 file changed, 3 insertions(+)drivers/mfd/palmas.c +0
-0drivers/mfd/palmas.c static void palmas_i2c_remove(struct i2c_client *i2c) · line 681
Quoted 5 lines
drivers/mfd/palmas.c +2
-0@@ -677,6 +677,9 @@ static void palmas_i2c_remove(struct i2c_client *i2c)struct palmas *palmas =i2c_get_clientdata (i2c);int i; +if (i2c->dev.of_node) +devm_of_platform_depopulate (&i2c->dev);I think it would be nice to devm_*
regmap_add_irq_chip()instead.Quoted 11 lines
If you also convert the auxiliary I2C clients and '
pm_power_off' teardown to devm, you could droppalmas_i2c_remove()altogether.Quoted 4 lines
drivers/mfd/palmas.c +1
-0+regmap_del_irq_chip (palmas->irq, palmas->irq_data);for (i =1 ; i <PALMAS_NUM_CLIENTS ; i++) {Signature · 1 line
Lee Jones
Quoted 7 lines
The IRQ chip is registered before
devm_of_platform_populate(). Withdevm_regmap_add_irq_chip(), the children would be removed while their IRQ mappings are still valid.If the auxiliary I2C clients and the power-off handler use managed cleanup too, I think
palmas_i2c_remove()can go away. Is that what you had in mind? If so, I'll send a v2 for palmas along those lines.
Yes, that sounds about right.
Signature · 1 line
Lee Jones
PATCH 4/6 mfd: stmpe: Fix potential use-after-free during removal
In reply to Guangshuo Listmpe_remove() frees the IRQ domain before removing its children. Deactivating a child's interrupt can then access the freed domain. Remove the children before tearing down the domain and supplies.
This issue was found by our static analysis tool under development.
---
Build-tested the changed object with x86_64 defconfig plus COMPILE_TEST and the driver dependencies (W=1).
No runtime or fault-injection testing was performed.
drivers/mfd/stmpe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mfd/stmpe.c +2 -2
@@ -1486,6 +1486,8 @@ EXPORT_SYMBOL_GPL(stmpe_probe);void stmpe_remove (struct stmpe *stmpe) { +mfd_remove_devices (stmpe->dev); +if (stmpe->domain)irq_domain_remove (stmpe->domain);
@@ -1495,8 +1497,6 @@ void stmpe_remove(struct stmpe *stmpe)regulator_disable (stmpe->vcc);__stmpe_disable (stmpe,STMPE_BLOCK_ADC ); - -mfd_remove_devices (stmpe->dev); }EXPORT_SYMBOL_GPL (stmpe_remove);
[email protected]
AI reviewRe: [PATCH 4/6] mfd: stmpe: Fix potential use-after-free during removal
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
stmpe_remove()frees the IRQ domain before removing its children. Deactivating a child's interrupt can then access the freed domain. Remove the children before tearing down the domain and supplies.This issue was found by our static analysis tool under development.
Fixes 57bf2a312ab2 ("mfd: stmpe: Remove IRQ domain upon removal")Assisted-by OpenAI:gpt-6-astraSigned-off-by Guangshuo Li <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH 5/6 mfd: stmfx: Fix potential IRQ action leaks on removal
In reply to Guangshuo LiThe remove callback disposes IRQ mappings before device-managed MFD children are removed. Their later free_irq() calls cannot find the IRQ descriptors, potentially leaking interrupt actions. Remove the children explicitly before tearing down the IRQ domain.
This issue was found by our static analysis tool under development.
---
Build-tested the changed object with x86_64 defconfig plus COMPILE_TEST and the driver dependencies (W=1).
No runtime or fault-injection testing was performed.
drivers/mfd/stmfx.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/mfd/stmfx.c +5 -3
@@ -448,9 +448,9 @@ static int stmfx_probe(struct i2c_client *client)if (ret) goto err_chip_exit; - ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , - stmfx_cells,ARRAY_SIZE (stmfx_cells),NULL , -0 , stmfx->irq_domain); + ret =mfd_add_devices (dev,PLATFORM_DEVID_NONE , + stmfx_cells,ARRAY_SIZE (stmfx_cells),NULL , +0 , stmfx->irq_domain);if (ret) goto err_irq_exit;
@@ -466,6 +466,8 @@ static int stmfx_probe(struct i2c_client *client)static void stmfx_remove (struct i2c_client *client) { +mfd_remove_devices (&client->dev); +stmfx_irq_exit (client);stmfx_chip_exit (client);
[email protected]
AI reviewRe: [PATCH 5/6] mfd: stmfx: Fix potential IRQ action leaks on removal
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
The remove callback disposes IRQ mappings before device-managed MFD children are removed. Their later
free_irq()calls cannot find the IRQ descriptors, potentially leaking interrupt actions. Remove the children explicitly before tearing down the IRQ domain.This issue was found by our static analysis tool under development.
Fixes 06252ade9156 ("mfd: Add ST Multi-Function eXpander (STMFX) core driver")Assisted-by OpenAI:gpt-6-astraSigned-off-by Guangshuo Li <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH 6/6 mfd: wm8994: Fix potential use-after-free during removal
In reply to Guangshuo LiThe IRQ chip is deleted before the codec child is removed. The codec's IRQ cleanup can then use the freed IRQ-chip data to look up interrupt numbers. Remove normal children before deleting the IRQ chip, and keep the LDO children until their regulator consumers have been released. Use late removal on probe failure as well to clean up the LDO children.
This issue was found by our static analysis tool under development.
---
Build-tested the changed object with x86_64 defconfig plus COMPILE_TEST and the driver dependencies (W=1).
No runtime or fault-injection testing was performed.
drivers/mfd/wm8994-core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/mfd/wm8994-core.c +5 -2
@@ -29,11 +29,13 @@static const struct mfd_cell wm8994_regulator_devs[] = { { .name ="wm8994-ldo" , + .level =MFD_DEP_LEVEL_HIGH , .id =0 , .pm_runtime_no_callbacks = true, }, { .name ="wm8994-ldo" , + .level =MFD_DEP_LEVEL_HIGH , .id =1 , .pm_runtime_no_callbacks = true, },
@@ -586,7 +588,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) err_regulator_free:regulator_bulk_free (wm8994->num_supplies, wm8994->supplies); err: -mfd_remove_devices (wm8994->dev); +mfd_remove_devices_late (wm8994->dev);return ret; }
@@ -595,10 +597,11 @@ static void wm8994_device_exit(struct wm8994 *wm8994)pm_runtime_get_sync (wm8994->dev);pm_runtime_disable (wm8994->dev);pm_runtime_put_noidle (wm8994->dev); +mfd_remove_devices (wm8994->dev);wm8994_irq_exit (wm8994);regulator_bulk_disable (wm8994->num_supplies, wm8994->supplies);regulator_bulk_free (wm8994->num_supplies, wm8994->supplies); -mfd_remove_devices (wm8994->dev); +mfd_remove_devices_late (wm8994->dev); }static const struct of_device_id wm8994_of_match[] = {
[email protected]
AI reviewRe: [PATCH 6/6] mfd: wm8994: Fix potential use-after-free during removal
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
The IRQ chip is deleted before the codec child is removed. The codec's IRQ cleanup can then use the freed IRQ-chip data to look up interrupt numbers. Remove normal children before deleting the IRQ chip, and keep the LDO children until their regulator consumers have been released. Use late removal on probe failure as well to clean up the LDO children.
Quoted 6 lines
This issue was found by our static analysis tool under development.
Fixes bb63f7d33d35 ("mfd: wm8994-core: Disable regulators before removing them")Assisted-by OpenAI:gpt-6-astraSigned-off-by Guangshuo Li <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Re: (subset) [PATCH 0/6] mfd: Fix potential cleanup ordering and lifetime bugs
In reply to Guangshuo LiQuoted 14 lines · Guangshuo Li
Remove child devices while their IRQ providers are still available, and avoid deleting a managed IRQ chip twice.
The changed driver objects were build-tested. No hardware testing was performed.
Guangshuo Li (6):
mfd: da9055: Fix potential use-after-free during removal
mfd: atc260x: Fix potential use-after-free on probe failure
mfd: palmas: Fix potential IRQ action leaks on removal
mfd: stmpe: Fix potential use-after-free during removal
mfd: stmfx: Fix potential IRQ action leaks on removal
mfd: wm8994: Fix potential use-after-free during removal
Quoted 1 line
[...]
Applied, thanks!
[1/6] mfd: da9055: Fix potential use-after-free during removal
commit: e8fe9e8397a935554eb61504934c76f9f7c32fc8
[2/6] mfd: atc260x: Fix potential use-after-free on probe failure
commit: dc3431a385007486413d1194d36ebe9d83790b78
[4/6] mfd: stmpe: Fix potential use-after-free during removal
commit: 259e272733575dbb4946829ad06eef6782ae91be
[5/6] mfd: stmfx: Fix potential IRQ action leaks on removal
commit: 1235c2932f71553486eab2b76dbf40806cd2d345
[6/6] mfd: wm8994: Fix potential use-after-free during removal
commit: 4c46825cdb45520f3a25f760e5c95f7b08191221--
Lee Jones [李琼斯]