]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
usb: gadget: rcar: Fix gadget registration lifecycle in remove
authorMichele Bisogno <micbis.openwrt@gmail.com>
Sun, 26 Apr 2026 07:43:17 +0000 (09:43 +0200)
committerMarek Vasut <marek.vasut+usb@mailbox.org>
Sun, 26 Apr 2026 15:52:36 +0000 (17:52 +0200)
The driver currently fails to unregister the USB gadget when the
device is removed or the driver is unbound. This leads to dangling
pointers in the UDC core and potential memory corruption.

Add a call to usb_del_gadget_udc() in the remove path to ensure
a clean teardown of the gadget interface.

Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Signed-off-by: Michele Bisogno <micbis.openwrt@gmail.com>
drivers/usb/gadget/rcar/common.c

index 2ba022a3f2cd59cc749d95b6688a0ef04d310b24..d40d6736a54cc16ab0b2bfd0447142da4024fe4f 100644 (file)
@@ -447,8 +447,11 @@ err_clk:
 static int usbhs_udc_otg_remove(struct udevice *dev)
 {
        struct usbhs_priv_otg_data *priv = dev_get_priv(dev);
+       struct usb_gadget *gadget;
 
        usbhs_rcar3_power_ctrl(&priv->usbhs_priv, false);
+       gadget = usbhsg_get_gadget(&priv->usbhs_priv);
+       usb_del_gadget_udc(gadget);
        usbhs_mod_remove(&priv->usbhs_priv);
        usbhs_fifo_remove(&priv->usbhs_priv);
        usbhs_pipe_remove(&priv->usbhs_priv);