mfd: da9150: balance IRQ wake on teardown
Subsystems (2)
PATCH 1/1 mfd: da9150: balance IRQ wake on teardown
DA9150 enables IRQ wake after registering its regmap IRQ chip, but does not disable it on a later probe failure or driver removal. This leaves the wake depth elevated after the handler is removed, and repeated bind attempts can accumulate the imbalance.
Remember whether enabling IRQ wake succeeded and balance only a successful call. Remove MFD children first so their nested IRQ users are gone, then disable wake before removing the regmap IRQ chip. Preserve the existing non-fatal behavior when IRQ wake cannot be enabled.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/mfd/da9150-core.c | 9 +++++++-- include/linux/mfd/da9150/core.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/mfd/da9150-core.c +7 -2
@@ -450,7 +450,8 @@ static int da9150_probe(struct i2c_client *client) da9150->irq_base =regmap_irq_chip_get_base (da9150->regmap_irq_data); -enable_irq_wake (da9150->irq); +if (!enable_irq_wake (da9150->irq)) + da9150->irq_wake_enabled = true; ret = mfd_add_devices(da9150->dev, -1, da9150_devs, ARRAY_SIZE(da9150_devs), NULL,
@@ -463,6 +464,8 @@ static int da9150_probe(struct i2c_client *client)return 0 ; mfd_fail: +if (da9150->irq_wake_enabled) +disable_irq_wake (da9150->irq);regmap_del_irq_chip (da9150->irq, da9150->regmap_irq_data); regmap_irq_fail:i2c_unregister_device (da9150->core_qif);
@@ -474,8 +477,10 @@ static void da9150_remove(struct i2c_client *client) {struct da9150 *da9150 =i2c_get_clientdata (client); -regmap_del_irq_chip (da9150->irq, da9150->regmap_irq_data);mfd_remove_devices (da9150->dev); +if (da9150->irq_wake_enabled) +disable_irq_wake (da9150->irq); +regmap_del_irq_chip (da9150->irq, da9150->regmap_irq_data);i2c_unregister_device (da9150->core_qif); }
include/linux/mfd/da9150/core.h +1 -0
@@ -65,6 +65,7 @@ struct da9150 {struct regmap_irq_chip_data *regmap_irq_data;int irq;int irq_base; +bool irq_wake_enabled; };/* Device I/O - Query Interface for FG and standard register access */
Signature · 1 line
2.47.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [Low] The commit message description is not capitalized, violating the MFD subsystem guidelines.
Pre-existing issues:
- [High] The global static mfd_cell array da9150_devs is not const and is dynamically modified during probe, violating MFD guidelines and introducing data races/state corruption.
- [High] da9150_reg_read() returns an uninitialized value on regmap_read() failure, which is then used to compute an I2C device address.
--
commit e761f00f1bf078aef3d54fe1deeb793b0138ed73
Author: Myeonghun Pak <[email protected]>
mfd: da9150: balance IRQ wake on teardown
This commit ensures that IRQ wake is properly disabled on probe failure or driver removal if it was successfully enabled. It prevents wake depth imbalance by tracking the success of enable_irq_wake.
Quoted 1 line
mfd: da9150: balance IRQ wake on teardown
[Severity: Low]
This isn't a bug, but MFD subsystem guidelines require the commit description to be capitalized. Should the subject line be formatted as mfd: da9150:
Balance IRQ wake on teardown?
Quoted 5 lines
drivers/mfd/da9150-core.c +0
-0
drivers/mfd/da9150-core.c static int da9150_probe(struct i2c_client *client) · line 457
Quoted 9 lines
drivers/mfd/da9150-core.c +2
-1@@ -450,7 +450,8 @@ static int da9150_probe(struct i2c_client *client) da9150->irq_base =regmap_irq_chip_get_base (da9150->regmap_irq_data); -enable_irq_wake (da9150->irq); +if (!enable_irq_wake (da9150->irq)) + da9150->irq_wake_enabled = true; ret = mfd_add_devices(da9150->dev, -1, da9150_devs, ARRAY_SIZE(da9150_devs), NULL,
[Severity: High]
This is a pre-existing issue, but I noticed da9150_devs is a global array that gets dynamically modified during probe:
drivers/mfd/da9150-core.c:da9150_probe() {
...
da9150_devs[DA9150_FG_IDX].platform_data = pdata->fg_pdata;
...
}
Does modifying a shared global mfd_cell array during probe corrupt the state for all subsequent instances of the device? If a second da9150 device is probed without its own platform data, it seems it would incorrectly inherit the platform_data assigned to the first device, potentially leading to incorrect hardware configuration or use-after-free conditions.
[Severity: High]
This is also a pre-existing issue, but looking earlier in da9150_probe(), it uses da9150_reg_read() to get the qif_addr:
drivers/mfd/da9150-core.c:da9150_probe() {
...
qif_addr = da9150_reg_read(da9150, DA9150_CORE2WIRE_CTRL_A); qif_addr = (qif_addr & DA9150_CORE_BASE_ADDR_MASK) >> 1; qif_addr |= DA9150_QIF_I2C_ADDR_LSB; da9150->core_qif = i2c_new_dummy_device(client->adapter, qif_addr);
...
}
If regmap_read() fails inside da9150_reg_read(), it leaves val unassigned:
drivers/mfd/da9150-core.c:da9150_reg_read() {
int val, ret;
ret = regmap_read(da9150->regmap, reg, &val);
...
return val;
}Can this lead to the driver registering a dummy device at an unpredictable I2C address derived from an uninitialized stack variable? It seems subsequent reads or writes to the QIF interface could target this random address, potentially corrupting the state of another hardware device on the bus.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Lee Jones
maintainerQuoted 28 lines · Myeonghun Pak
DA9150 enables IRQ wake after registering its regmap IRQ chip, but does not disable it on a later probe failure or driver removal. This leaves the wake depth elevated after the handler is removed, and repeated bind attempts can accumulate the imbalance.
Remember whether enabling IRQ wake succeeded and balance only a successful call. Remove MFD children first so their nested IRQ users are gone, then disable wake before removing the regmap IRQ chip. Preserve the existing non-fatal behavior when IRQ wake cannot be enabled.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
Fixes b8fce55c09d3 ("mfd: Add support for DA9150 combined charger & fuel-gauge device")Assisted-by OpenAI:GPT-5.6Co-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>--- drivers/mfd/da9150-core.c | 9 +++++++-- include/linux/mfd/da9150/core.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-)drivers/mfd/da9150-core.c +0
-0
drivers/mfd/da9150-core.c static int da9150_probe(struct i2c_client *client) · line 454
Quoted 6 lines
drivers/mfd/da9150-core.c +2
-1@@ -450,7 +450,8 @@ static int da9150_probe(struct i2c_client *client) da9150->irq_base =regmap_irq_chip_get_base (da9150->regmap_irq_data); -enable_irq_wake (da9150->irq); +if (!enable_irq_wake (da9150->irq)) + da9150->irq_wake_enabled = true;
da9150->irq_wake_enabled = !enable_irq_wake(da9150->irq);
drivers/mfd/da9150-core.c static int da9150_probe(struct i2c_client *client) · line 468
Quoted 8 lines
drivers/mfd/da9150-core.c +2
-0ret = mfd_add_devices(da9150->dev, -1, da9150_devs, ARRAY_SIZE(da9150_devs), NULL,@@ -463,6 +464,8 @@ static int da9150_probe(struct i2c_client *client)return 0 ; mfd_fail: +if (da9150->irq_wake_enabled) +disable_irq_wake (da9150->irq);
Or drop all of the checks and just call disable_irq_wake() on the error path.
Quoted 30 lines
drivers/mfd/da9150-core.c +3
-1regmap_del_irq_chip (da9150->irq, da9150->regmap_irq_data); regmap_irq_fail:i2c_unregister_device (da9150->core_qif);@@ -474,8 +477,10 @@ static void da9150_remove(struct i2c_client *client) {struct da9150 *da9150 =i2c_get_clientdata (client); -regmap_del_irq_chip (da9150->irq, da9150->regmap_irq_data);mfd_remove_devices (da9150->dev); +if (da9150->irq_wake_enabled) +disable_irq_wake (da9150->irq); +regmap_del_irq_chip (da9150->irq, da9150->regmap_irq_data);i2c_unregister_device (da9150->core_qif); }include/linux/mfd/da9150/core.h +1
-0@@ -65,6 +65,7 @@ struct da9150 {struct regmap_irq_chip_data *regmap_irq_data;int irq;int irq_base; +bool irq_wake_enabled; };/* Device I/O - Query Interface for FG and standard register access */ Signature · 1 line
2.47.1
Signature · 1 line
Lee Jones