[PATCH v4 1/3] usb: gadget: rcar: Fix gadget registration lifecycle in remove
Michele Bisogno
micbis.openwrt at gmail.com
Thu Apr 23 10:05:00 CEST 2026
On Thu, 23 Apr 2026 at 05:02, Marek Vasut <marek.vasut at mailbox.org> wrote:
>
> On 4/22/26 6:59 PM, Michele Bisogno wrote:
> > 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.
> >
> > Signed-off-by: Michele Bisogno <micbis.openwrt at gmail.com>
> > ---
> > drivers/usb/gadget/rcar/common.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/usb/gadget/rcar/common.c b/drivers/usb/gadget/rcar/common.c
> > index 2ba022a3f2c..f7b34f0485f 100644
> > --- a/drivers/usb/gadget/rcar/common.c
> > +++ b/drivers/usb/gadget/rcar/common.c
> > @@ -447,8 +447,12 @@ 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);
>
> One more nitpick, usbhsg_get_gadget() can never return NULL, so this
> test for NULL is unnecessary, please drop it.
OK.
More information about the U-Boot
mailing list