Skip to contentSkip to conversation

power: supply: sc2731_charger: cancel work on remove

PATCH In review Hongyan Xu 2 participants 2 messages Jul 28 – Jul 29

Subsystems (2)
lore
Share & tools
lore

Hongyan Xu

author
#0 lore raw

PATCH 1/1 power: supply: sc2731_charger: cancel work on remove

The USB notifier and initial charger detection can schedule info->work. The remove path unregisters the notifier, but does not cancel queued or running work before the devm-allocated driver data is released.

Set the platform drvdata used by remove, then cancel the work after unregistering the notifier.

This issue was found by a static analysis tool.

---
 drivers/power/supply/sc2731_charger.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/power/supply/sc2731_charger.c +2 -0
index 58b86fd78..2b25e44da 100644
@@ -466,6 +466,7 @@ static int sc2731_charger_probe(struct platform_device *pdev)
 	mutex_init(&info->lock);
 	info->dev = &pdev->dev;
 	INIT_WORK(&info->work, sc2731_charger_work);
+	platform_set_drvdata(pdev, info);
 
 	info->regmap = dev_get_regmap(pdev->dev.parent, NULL);
 	if (!info->regmap) {
@@ -516,6 +517,7 @@ static void sc2731_charger_remove(struct platform_device *pdev)
 	struct sc2731_charger_info *info = platform_get_drvdata(pdev);
 
 	usb_unregister_notifier(info->usb_phy, &info->usb_notify);
+	cancel_work_sync(&info->work);
 }
 
 static const struct of_device_id sc2731_charger_of_match[] = {
Signature · 1 line
2.50.1.windows.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Hongyan Xu

The USB notifier and initial charger detection can schedule info->work. The remove path unregisters the notifier, but does not cancel queued or running work before the devm-allocated driver data is released.

Set the platform drvdata used by remove, then cancel the work after unregistering the notifier.

This issue was found by a static analysis tool.

---

Good catch. Please also add a Fixes tag, with that:

Quoted 23 lines
  drivers/power/supply/sc2731_charger.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/power/supply/sc2731_charger.c +2 -0
index 58b86fd78..2b25e44da 100644
@@ -466,6 +466,7 @@ static int sc2731_charger_probe(struct platform_device *pdev)
  	mutex_init(&info->lock);
  	info->dev = &pdev->dev;
  	INIT_WORK(&info->work, sc2731_charger_work);
+	platform_set_drvdata(pdev, info);
 
  	info->regmap = dev_get_regmap(pdev->dev.parent, NULL);
  	if (!info->regmap) {
@@ -516,6 +517,7 @@ static void sc2731_charger_remove(struct platform_device *pdev)
  	struct sc2731_charger_info *info = platform_get_drvdata(pdev);
 
  	usb_unregister_notifier(info->usb_phy, &info->usb_notify);
+	cancel_work_sync(&info->work);
  }
 
  static const struct of_device_id sc2731_charger_of_match[] = {