Re: [PATCH] usb: gadget: f_tcm: Cancel delayed set_alt work on teardown

From: Cen Zhang

Date: Sat Jun 27 2026 - 06:39:50 EST


Hi Thinh,

Thinh Nguyen <Thinh.Nguyen@xxxxxxxxxxxx> 于2026年6月27日周六 08:08写道:
>
> Couldn't a race still happen here? I don't think you can just use
> cancel_work_sync in tcm_disable here.
>

You're right. tcm_disable() can be called while the composite device lock is
held, so using cancel_work_sync() there is not safe.

I reworked this in v2 by using a small delayed-set-alt state machine:
tcm_disable() now only uses a non-sleeping cancellation path. If the work is
still queued, it is cancelled and cleaned up immediately. If it is already
running, it is marked cancelled and the worker owns the cleanup before
returning. cancel_work_sync() is only used from unbind/free paths where
sleeping is safe.

I also added Cc: stable@xxxxxxxxxxxxxxx as suggested.

Thanks,
Cen Zhang