From: Sebastian Reichel <sebastian.reichel@collabora.com>
To: Yaohan Li <shunsheng1218@gmail.com>
Cc: hansg@kernel.org, marex@denx.de, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] power: supply: bq25890: cancel pump work before supply removal
Date: Fri, 6 Nov 2026 01:37:41 +0100 [thread overview]
Message-ID: <au0gsSfR64U3Bs3S@venus> (raw)
In-Reply-To: <179378565123.72475.2497991563887142080@gmail.com>
Hi,
On Wed, Nov 04, 2026 at 05:47:31PM +0800, Yaohan Li wrote:
> 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;
Use devm_delayed_work_autocancel() (and drop the INIT_DELAYED_WORK).
-- Sebastian
> +
> ret = devm_request_threaded_irq(dev, client->irq, NULL,
> bq25890_irq_handler_thread,
> IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
> --
> 2.34.1
>
prev parent reply other threads:[~2026-11-06 0:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 9:47 Yaohan Li
2026-11-06 0:37 ` Sebastian Reichel [this message]
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=au0gsSfR64U3Bs3S@venus \
--to=sebastian.reichel@collabora.com \
--cc=hansg@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=marex@denx.de \
--cc=shunsheng1218@gmail.com \
/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®