mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 22:14:03 +02:00
power: supply: bq24257: fix use-after-free on remove
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 threaded handler can still fire; that
handler reschedules the work and dereferences bq, so the work runs
against freed memory once devm frees bq.
Make the delayed work device-managed with devm_delayed_work_autocancel(),
registered before the interrupt request. The devm cleanup then releases
the interrupt first, so the handler can no longer reschedule the work,
and cancels the work before bq is freed. The explicit
cancel_delayed_work_sync() in remove() is no longer needed and is dropped.
Found by static analysis.
Fixes: 2219a93596 ("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>
Link: https://patch.msgid.link/20260731143554.334179-1-fanwu01@zju.edu.cn
Link: https://patch.msgid.link/20260801051958.354528-1-fanwu01@zju.edu.cn
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
4e40befedf
commit
9d34c9d660
|
|
@ -18,6 +18,7 @@
|
|||
#include <linux/gpio/consumer.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/devm-helpers.h>
|
||||
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/of.h>
|
||||
|
|
@ -1003,10 +1004,6 @@ static int bq24257_probe(struct i2c_client *client)
|
|||
if (bq->info->chip == BQ24250)
|
||||
bq->iilimit_autoset_enable = false;
|
||||
|
||||
if (bq->iilimit_autoset_enable)
|
||||
INIT_DELAYED_WORK(&bq->iilimit_setup_work,
|
||||
bq24257_iilimit_setup_work);
|
||||
|
||||
/*
|
||||
* The BQ24250 doesn't have a dedicated Power Good (PG) pin so let's
|
||||
* not probe for it and instead use a SW-based approach to determine
|
||||
|
|
@ -1047,6 +1044,14 @@ static int bq24257_probe(struct i2c_client *client)
|
|||
return ret;
|
||||
}
|
||||
|
||||
if (bq->iilimit_autoset_enable) {
|
||||
ret = devm_delayed_work_autocancel(dev,
|
||||
&bq->iilimit_setup_work,
|
||||
bq24257_iilimit_setup_work);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = devm_request_threaded_irq(dev, client->irq, NULL,
|
||||
bq24257_irq_handler_thread,
|
||||
IRQF_TRIGGER_FALLING |
|
||||
|
|
@ -1062,9 +1067,6 @@ static void bq24257_remove(struct i2c_client *client)
|
|||
{
|
||||
struct bq24257_device *bq = i2c_get_clientdata(client);
|
||||
|
||||
if (bq->iilimit_autoset_enable)
|
||||
cancel_delayed_work_sync(&bq->iilimit_setup_work);
|
||||
|
||||
bq24257_field_write(bq, F_RESET, 1); /* reset to defaults */
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user