Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: typec: thunderbolt: cancel work on driver removal
@ 2026-08-06  6:07 Hongyan Xu
  2026-08-12  8:53 ` Heikki Krogerus
  0 siblings, 1 reply; 2+ messages in thread
From: Hongyan Xu @ 2026-08-06  6:07 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman
  Cc: Benson Leung, Abhishek Pandit-Subedi, linux-usb, linux-kernel,
	stable, jianhao.xu, 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")
Cc: stable@vger.kernel.org
Signed-off-by: Hongyan Xu <getshell@seu.edu.cn>
---
 drivers/usb/typec/altmodes/thunderbolt.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/typec/altmodes/thunderbolt.c b/drivers/usb/typec/altmodes/thunderbolt.c
index 32250b94262a..57c8dff0c51f 100644
--- a/drivers/usb/typec/altmodes/thunderbolt.c
+++ b/drivers/usb/typec/altmodes/thunderbolt.c
@@ -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]);
-- 
2.50.1.windows.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: typec: thunderbolt: cancel work on driver removal
  2026-08-06  6:07 [PATCH] usb: typec: thunderbolt: cancel work on driver removal Hongyan Xu
@ 2026-08-12  8:53 ` Heikki Krogerus
  0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2026-08-12  8:53 UTC (permalink / raw)
  To: Hongyan Xu
  Cc: Greg Kroah-Hartman, Benson Leung, Abhishek Pandit-Subedi,
	linux-usb, linux-kernel, stable, jianhao.xu

On Thu, Aug 06, 2026 at 02:07:12PM +0800, Hongyan Xu wrote:
> 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")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hongyan Xu <getshell@seu.edu.cn>
> ---
>  drivers/usb/typec/altmodes/thunderbolt.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/usb/typec/altmodes/thunderbolt.c b/drivers/usb/typec/altmodes/thunderbolt.c
> index 32250b94262a..57c8dff0c51f 100644
> --- a/drivers/usb/typec/altmodes/thunderbolt.c
> +++ b/drivers/usb/typec/altmodes/thunderbolt.c
> @@ -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/20260802014959.416687-1-fanwu01@zju.edu.cn/

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-12  8:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-06  6:07 [PATCH] usb: typec: thunderbolt: cancel work on driver removal Hongyan Xu
2026-08-12  8:53 ` Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox