[PATCH v2 2/3] power: supply: axp20x_usb_power: drain vbus_detect work before unregistering the supply
hyunjungg
hj351016 at gmail.com
Sun Nov 8 20:42:11 PST 2026
From: Hyunjung Ko <hj351016 at 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 at vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016 at 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
More information about the Linux-mediatek
mailing list