Skip to contentSkip to conversation

mfd: da9150: Balance IRQ wake on teardown

PATCH Applied Myeonghun Pak 3 participants 3 messages Sep 23 – Sep 24

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

Fixes b8fce55c09d3 ("mfd: Add support for DA9150 combined charger & fuel-gauge device")
Assisted-by LLM

---
Changes in v2:
- Record enable_irq_wake() success in one assignment. (Lee Jones)
- Keep the irq_wake_enabled checks. disable_irq_wake() after a failed enable warns about an unbalanced wake disable.

 drivers/mfd/da9150-core.c       | 8 ++++++--
 include/linux/mfd/da9150/core.h | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/mfd/da9150-core.c +6 -2
index 5c59cc869fb3e2a6ac5aaea7426f38241cb92cb1..19325d72a27e7e12aa8acb121b5bc115305b4231 100644
@@ -450,7 +450,7 @@ 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);
+	da9150->irq_wake_enabled = !enable_irq_wake(da9150->irq);
 
 	ret = mfd_add_devices(da9150->dev, -1, da9150_devs,
 			      ARRAY_SIZE(da9150_devs), NULL,
@@ -463,6 +463,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 +476,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
index d116d5f3ef561288756477e7170400b47d65e180..369698036d1aa5d1722f6459946f38abfc8cf350 100644
@@ -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 · 3 lines
2.47.1

base-commit: df2908090cda368b01ff43709f51890076c56157
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines

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.

Quoted 8 lines

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 LLM

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Applied
#2 lore raw

Re: (subset) [PATCH v2] mfd: da9150: Balance IRQ wake on teardown

In reply to Myeonghun Pak
Quoted 11 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.

[...]

Applied, thanks!

[1/1] mfd: da9150: Balance IRQ wake on teardown

      commit: ef464f82f3aecad4071af71074b2ceb77ffbb609

--
Lee Jones [李琼斯]