* [PATCH v2 1/3] power: supply: ltc2941: drain poll work before unregistering the supply
2026-11-09 4:42 [PATCH v2 0/3] power: supply: fix work-vs-devres teardown use-after-free hyunjungg
@ 2026-11-09 4:42 ` hyunjungg
2026-11-09 4:42 ` [PATCH v2 2/3] power: supply: axp20x_usb_power: drain vbus_detect " hyunjungg
2026-11-09 4:42 ` [PATCH v2 3/3] power: supply: mt6360_charger: drain chrdet_work " hyunjungg
2 siblings, 0 replies; 4+ messages in thread
From: hyunjungg @ 2026-11-09 4:42 UTC (permalink / raw)
To: Sebastian Reichel, linux-pm
Cc: Sebastian Reichel, Chen-Yu Tsai, Matthias Brugger,
AngeloGioacchino Del Regno, linux-arm-kernel, linux-mediatek,
linux-kernel, Hyunjung Ko, stable
From: Hyunjung Ko <hj351016@gmail.com>
ltc294x_i2c_probe() registers the poll work for devm cancellation before
devm_power_supply_register(). devres unwinds in reverse, so on unbind the
power supply is freed first and the work cancelled last. ltc294x_work()
re-queues itself and calls power_supply_changed(info->supply), so a poll
instance running in that window dereferences the freed supply.
Register the work cancellation after the power supply so devres drains it
first. Nothing queues the work before the schedule_delayed_work() that
follows, so the move is safe.
Fixes: 6d0c5de2fd84 ("power: supply: Clean-up few drivers by using managed work init")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
diff --git a/drivers/power/supply/ltc2941-battery-gauge.c b/drivers/power/supply/ltc2941-battery-gauge.c
index 6ebb555..8f8a8f6 100644
--- a/drivers/power/supply/ltc2941-battery-gauge.c
+++ b/drivers/power/supply/ltc2941-battery-gauge.c
@@ -531,11 +531,6 @@ static int ltc294x_i2c_probe(struct i2c_client *client)
psy_cfg.drv_data = info;
- ret = devm_delayed_work_autocancel(&client->dev, &info->work,
- ltc294x_work);
- if (ret)
- return ret;
-
ret = ltc294x_reset(info, prescaler_exp);
if (ret < 0)
return dev_err_probe(&client->dev, ret,
@@ -547,6 +542,11 @@ static int ltc294x_i2c_probe(struct i2c_client *client)
return dev_err_probe(&client->dev, PTR_ERR(info->supply),
"failed to register ltc2941\n");
+ ret = devm_delayed_work_autocancel(&client->dev, &info->work,
+ ltc294x_work);
+ if (ret)
+ return ret;
+
schedule_delayed_work(&info->work, LTC294X_WORK_DELAY * HZ);
return 0;
--
2.43.0
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 2/3] power: supply: axp20x_usb_power: drain vbus_detect work before unregistering the supply
2026-11-09 4:42 [PATCH v2 0/3] power: supply: fix work-vs-devres teardown use-after-free hyunjungg
2026-11-09 4:42 ` [PATCH v2 1/3] power: supply: ltc2941: drain poll work before unregistering the supply hyunjungg
@ 2026-11-09 4:42 ` hyunjungg
2026-11-09 4:42 ` [PATCH v2 3/3] power: supply: mt6360_charger: drain chrdet_work " hyunjungg
2 siblings, 0 replies; 4+ messages in thread
From: hyunjungg @ 2026-11-09 4:42 UTC (permalink / raw)
To: Sebastian Reichel, linux-pm
Cc: Sebastian Reichel, Chen-Yu Tsai, Matthias Brugger,
AngeloGioacchino Del Regno, linux-arm-kernel, linux-mediatek,
linux-kernel, Hyunjung Ko, stable
From: Hyunjung Ko <hj351016@gmail.com>
axp20x_usb_power_probe() registers the vbus_detect poll work for devm
cancellation before devm_power_supply_register(). devres unwinds in
reverse, so on unbind the power supply is freed first and the work
cancelled last. The handler calls power_supply_changed(power->supply) and
re-queues itself (and is also queued from the USB power IRQ), so an
instance running in that window dereferences the freed supply.
Register the work cancellation after the power supply, matching the
"request irqs after registering" ordering already used below.
Fixes: 6d0c5de2fd84 ("power: supply: Clean-up few drivers by using managed work init")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c
index 7625366104bc..f6a7dcbd5a01 100644
--- a/drivers/power/supply/axp20x_usb_power.c
+++ b/drivers/power/supply/axp20x_usb_power.c
@@ -979,11 +979,6 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
if (ret)
return ret;
- ret = devm_delayed_work_autocancel(dev, &power->vbus_detect,
- axp_data->axp20x_read_vbus);
- if (ret)
- return ret;
-
if (power->vbus_mon_bit) {
/* Enable vbus valid checking */
ret = regmap_field_write(power->vbus_mon_bit, 1);
@@ -1018,6 +1013,11 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
return dev_err_probe(dev, PTR_ERR(power->supply),
"Failed to register power supply\n");
+ ret = devm_delayed_work_autocancel(dev, &power->vbus_detect,
+ axp_data->axp20x_read_vbus);
+ if (ret)
+ return ret;
+
/* Request irqs after registering, as irqs may trigger immediately */
for (i = 0; i < axp_data->num_irq_names; i++) {
irq = platform_get_irq_byname(pdev, axp_data->irq_names[i]);
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 3/3] power: supply: mt6360_charger: drain chrdet_work before unregistering the supply
2026-11-09 4:42 [PATCH v2 0/3] power: supply: fix work-vs-devres teardown use-after-free hyunjungg
2026-11-09 4:42 ` [PATCH v2 1/3] power: supply: ltc2941: drain poll work before unregistering the supply hyunjungg
2026-11-09 4:42 ` [PATCH v2 2/3] power: supply: axp20x_usb_power: drain vbus_detect " hyunjungg
@ 2026-11-09 4:42 ` hyunjungg
2 siblings, 0 replies; 4+ messages in thread
From: hyunjungg @ 2026-11-09 4:42 UTC (permalink / raw)
To: Sebastian Reichel, linux-pm
Cc: Sebastian Reichel, Chen-Yu Tsai, Matthias Brugger,
AngeloGioacchino Del Regno, linux-arm-kernel, linux-mediatek,
linux-kernel, Hyunjung Ko, stable
From: Hyunjung Ko <hj351016@gmail.com>
mt6360_charger_probe() registers chrdet_work for devm cancellation before
devm_power_supply_register(). devres unwinds in reverse, so on unbind the
power supply is freed first and the work cancelled last.
mt6360_chrdet_work() calls power_supply_changed(mci->psy), so the work
running in that window dereferences the freed supply.
Register the work cancellation after the power supply so devres drains it
first. chrdet_work is only scheduled later in probe, so the move is safe.
Fixes: 0402e8ebb8b8 ("power: supply: mt6360_charger: add MT6360 charger support")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
diff --git a/drivers/power/supply/mt6360_charger.c b/drivers/power/supply/mt6360_charger.c
index b4d462343151..71c60ba012df 100644
--- a/drivers/power/supply/mt6360_charger.c
+++ b/drivers/power/supply/mt6360_charger.c
@@ -790,9 +790,6 @@ static int mt6360_charger_probe(struct platform_device *pdev)
mci->vinovp = 6500000;
mutex_init(&mci->chgdet_lock);
platform_set_drvdata(pdev, mci);
- ret = devm_work_autocancel(&pdev->dev, &mci->chrdet_work, mt6360_chrdet_work);
- if (ret)
- return dev_err_probe(&pdev->dev, ret, "Failed to set delayed work\n");
ret = device_property_read_u32(&pdev->dev, "richtek,vinovp-microvolt", &mci->vinovp);
if (ret)
@@ -828,6 +825,10 @@ static int mt6360_charger_probe(struct platform_device *pdev)
if (IS_ERR(mci->otg_rdev))
return PTR_ERR(mci->otg_rdev);
+ ret = devm_work_autocancel(&pdev->dev, &mci->chrdet_work, mt6360_chrdet_work);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "Failed to set delayed work\n");
+
schedule_work(&mci->chrdet_work);
return 0;
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread