[PATCH 0/2] Fix use after freed situation in UDC core

From: Wesley Cheng
Date: Fri Feb 28 2025 - 19:35:19 EST


commit 1ff24d40b3c3 ("usb: dwc3: gadget: Fix incorrect UDC state after
manual deconfiguration")

Added a use after freed situation due to the fact that the
usb_gadget_set_state() API queuing asynchronous work to be run at a later
time. When moving from device to host mode, the UDC is removed, and this
is the condition where this is seen. Relocate this fix from the DWC3
gadget, and apply it within the UDC core, so that we can properly manage
the gadget->work. It also makes sense, as during soft disconnection
sequence, the USB link is unavailable, so any UDC should reflect the
proper state.

Wesley Cheng (2):
Revert "usb: dwc3: gadget: Fix incorrect UDC state after manual
deconfiguration"
usb: gadget: udc: Update USB gadget state during soft disconnect

drivers/usb/dwc3/gadget.c | 2 --
drivers/usb/gadget/udc/core.c | 5 ++++-
2 files changed, 4 insertions(+), 3 deletions(-)