Skip to contentSkip to conversation

usb: typec: thunderbolt: cancel work on driver removal

PATCH In review Hongyan Xu 2 participants 2 messages Aug 6 – Aug 12

Subsystems (4)
lore
Share & tools
lore

Hongyan Xu

author
#0 lore raw

PATCH 1/1 usb: typec: thunderbolt: cancel work on driver removal

The probe and alternate mode callbacks can schedule tbt->work. The remove callback drops the cable and plug references without canceling that work, and the devres core then frees tbt. A pending or running work item can therefore dereference both released objects and the freed tbt allocation.

Cancel the work synchronously before dropping the referenced Type-C objects.

Fixes 100e25738659 ("usb: typec: Add driver for Thunderbolt 3 Alternate Mode")
---
 drivers/usb/typec/altmodes/thunderbolt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/typec/altmodes/thunderbolt.c +2 -0
index 32250b94262a..57c8dff0c51f 100644
@@ -303,6 +303,8 @@ static void tbt_altmode_remove(struct typec_altmode *alt)
 {
 	struct tbt_altmode *tbt = typec_altmode_get_drvdata(alt);
 
+	cancel_work_sync(&tbt->work);
+
 	for (int i = TYPEC_PLUG_SOP_PP; i >= 0; --i) {
 		if (tbt->plug[i])
 			typec_altmode_put_plug(tbt->plug[i]);
Signature · 1 line
2.50.1.windows.1
maintainer
#1 lore raw
Quoted 20 lines · Hongyan Xu

The probe and alternate mode callbacks can schedule tbt->work. The remove callback drops the cable and plug references without canceling that work, and the devres core then frees tbt. A pending or running work item can therefore dereference both released objects and the freed tbt allocation.

Cancel the work synchronously before dropping the referenced Type-C objects.

Fixes 100e25738659 ("usb: typec: Add driver for Thunderbolt 3 Alternate Mode")
---
 drivers/usb/typec/altmodes/thunderbolt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/typec/altmodes/thunderbolt.c +0 -0
index 32250b94262a..57c8dff0c51f 100644

drivers/usb/typec/altmodes/thunderbolt.c static void tbt_altmode_remove(struct typec_altmode *alt) · line 306

Quoted 4 lines
drivers/usb/typec/altmodes/thunderbolt.c +1 -0
@@ -303,6 +303,8 @@ static void tbt_altmode_remove(struct typec_altmode *alt)
 {
 	struct tbt_altmode *tbt = typec_altmode_get_drvdata(alt);
 
+	cancel_work_sync(&tbt->work);

There's already a fix for this one:
https://lore.kernel.org/linux-usb/[email protected]/

thanks,

Signature · 1 line
heikki