Skip to contentSkip to conversation

extcon: max77693: cancel cable detection work on detach

PATCH New Hongyan Xu 1 participant 1 message Jul 28

Subsystems (3)
lore
Share & tools
lore

Hongyan Xu

author
#0 lore raw

PATCH 1/1 extcon: max77693: cancel cable detection work on detach

max77693_muic_probe() queues wq_detcable after the MUIC has been initialized. The delayed work uses the driver private data and device resources, but the driver has no remove callback to cancel it. If the device is detached before the delayed detection runs, the work can run after the devm-managed data has started going away.

Initialize the delayed work with devm_delayed_work_autocancel() so the work is synchronously cancelled during device teardown.

This issue was found by a static analysis tool.

Fixes db1b9037424b ("extcon: MAX77693: Add extcon-max77693 driver to support Maxim MAX77693 MUIC device")
---
 drivers/extcon/extcon-max77693.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/extcon/extcon-max77693.c +5 -1
index 2c567e0b7b7..2dee37faa09 100644
@@ -1251,7 +1251,11 @@ static int max77693_muic_probe(struct platform_device *pdev)
 	 * After completing the booting of platform, the extcon provider
 	 * driver should notify cable state to upper layer.
 	 */
-	INIT_DELAYED_WORK(&info->wq_detcable, max77693_muic_detect_cable_wq);
+	ret = devm_delayed_work_autocancel(&pdev->dev, &info->wq_detcable,
+					   max77693_muic_detect_cable_wq);
+	if (ret)
+		return ret;
+
 	queue_delayed_work(system_power_efficient_wq, &info->wq_detcable,
 			delay_jiffies);
 
Signature · 1 line
2.50.1.windows.1