Skip to contentSkip to conversation

usb: typec: ucsi: glink: cancel pending work items on removal

PATCH New Nathan Rebello 1 participant 1 message Feb 27

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: typec: ucsi: glink: cancel pending work items on removal

pmic_glink_ucsi_remove() does not cancel notify_work and register_work before calling ucsi_unregister(). This can lead to a use-after-free if either work item executes after the backing data structures have been freed during teardown.

notify_work dereferences ucsi->ucsi in pmic_glink_ucsi_notify(), and register_work may call ucsi_unregister() a second time in pmic_glink_ucsi_register(), causing a double-free since ucsi_unregister() does not NULL the connector pointer after freeing.

All other UCSI backend drivers properly cancel their work items during teardown:
- cros_ec_ucsi.c cancels in both remove and destroy paths
- ucsi_ccg.c cancels pm_work and work in remove
- displayport.c cancels in remove_partner

ucsi_glink.c is the only backend that does not, despite initializing two work items in probe.

Add cancel_work_sync() calls for both work items before ucsi_unregister() to ensure no pending work executes during or after removal.

Fixes 62b5412b1f4a ("usb: typec: ucsi: add PMIC Glink UCSI driver")
---
 drivers/usb/typec/ucsi/ucsi_glink.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/typec/ucsi/ucsi_glink.c +3 -0
index 11b3e24e34e2..99e5ad54c6df 100644
@@ -463,6 +463,9 @@ static void pmic_glink_ucsi_remove(struct auxiliary_device *adev)
 {
 	struct pmic_glink_ucsi *ucsi = dev_get_drvdata(&adev->dev);
 
+	cancel_work_sync(&ucsi->notify_work);
+	cancel_work_sync(&ucsi->register_work);
+
 	/* Unregister first to stop having read & writes */
 	ucsi_unregister(ucsi->ucsi);
 }
Signature · 1 line
2.43.0.windows.1