Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH] power: supply: bq24257: fix use-after-free on remove
@ 2026-07-31 14:35 Fan Wu
  2026-07-31 21:29 ` Sebastian Reichel
  0 siblings, 1 reply; 2+ messages in thread
From: Fan Wu @ 2026-07-31 14:35 UTC (permalink / raw)
  To: linux-pm; +Cc: sre, laurentiu.palcu, krzk, linux-kernel, stable, Fan Wu

The STAT-pin interrupt is devm-managed, so it stays armed until the devm
cleanup that runs after remove() returns. remove() cancels
bq->iilimit_setup_work while the handler can still fire; the threaded
handler reschedules that work and dereferences bq, so the work runs
against freed memory once devm frees bq.

Call devm_free_irq() before canceling the work so the handler is quiesced
and cannot reschedule it after the cancel.

Found by static analysis.

Fixes: 2219a935963e ("power_supply: Add TI BQ24257 charger driver")
Cc: stable@vger.kernel.org
Assisted-by: Codex:gpt-5.6
Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>
---
 drivers/power/supply/bq24257_charger.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/power/supply/bq24257_charger.c b/drivers/power/supply/bq24257_charger.c
index 72f1bfea8d..b9110d5fe2 100644
--- a/drivers/power/supply/bq24257_charger.c
+++ b/drivers/power/supply/bq24257_charger.c
@@ -1064,6 +1064,7 @@ static void bq24257_remove(struct i2c_client *client)
 {
 	struct bq24257_device *bq = i2c_get_clientdata(client);
 
+	devm_free_irq(&client->dev, client->irq, bq);
 	if (bq->iilimit_autoset_enable)
 		cancel_delayed_work_sync(&bq->iilimit_setup_work);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-31 21:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-31 14:35 [PATCH] power: supply: bq24257: fix use-after-free on remove Fan Wu
2026-07-31 21:29 ` Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox