From: Yaohan Li <shunsheng1218@gmail.com>
To: sre@kernel.org
Cc: hansg@kernel.org, marex@denx.de, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] power: supply: bq25890: cancel pump work before supply removal
Date: Wed, 04 Nov 2026 17:47:31 +0800 [thread overview]
Message-ID: <179378565123.72475.2497991563887142080@gmail.com> (raw)
The existing devm cleanup for pump_express_work runs after the
managed power supply has been unregistered. A delayed or running pump
work item can therefore call power_supply_changed() with a freed
power_supply pointer.
Register an additional devm cleanup action after power-supply
registration, so devres reverse ordering drains the work while the
supply is still alive. Keep the original late cleanup as a backstop
for work that might be queued again during supplier teardown.
A KASAN test using a simulated I2C device and the real bq25890
driver reproduced the use-after-free before the change and not under
the corresponding teardown sequence afterward.
Fixes: a7aaa80098d5b7608 ("power: supply: bq25890: Ensure pump_express_work is cancelled on remove")
Assisted-by: ZCode:GLM-4
Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
---
drivers/power/supply/bq25890_charger.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
index f7510ada6b734..a3e35e036b97b 100644
--- a/drivers/power/supply/bq25890_charger.c
+++ b/drivers/power/supply/bq25890_charger.c
@@ -1459,6 +1459,23 @@ static void bq25890_non_devm_cleanup(void *data)
}
}
+static void bq25890_cancel_pump_express(void *data)
+{
+ struct bq25890_device *bq = data;
+
+ /*
+ * Cancel the delayed work while the power supply is still alive:
+ * bq25890_pump_express_work() calls power_supply_changed() at its
+ * end and must not run against an already released supply.
+ *
+ * bq25890_non_devm_cleanup() stays in place as well: it runs
+ * after the devres-managed power supply has been unregistered,
+ * catching work queued again from the supplier-change path
+ * between this cancel and the unregister.
+ */
+ cancel_delayed_work_sync(&bq->pump_express_work);
+}
+
static int bq25890_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
@@ -1531,6 +1548,10 @@ static int bq25890_probe(struct i2c_client *client)
if (ret < 0)
return dev_err_probe(dev, ret, "registering power supply\n");
+ ret = devm_add_action_or_reset(dev, bq25890_cancel_pump_express, bq);
+ if (ret)
+ return ret;
+
ret = devm_request_threaded_irq(dev, client->irq, NULL,
bq25890_irq_handler_thread,
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
--
2.34.1
reply other threads:[~2026-11-04 9:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179378565123.72475.2497991563887142080@gmail.com \
--to=shunsheng1218@gmail.com \
--cc=hansg@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=marex@denx.de \
--cc=sre@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®