Re: [PATCH] usb: gadget: f_hid: fix device reference leak in hidg_alloc()
From: Guangshuo Li
Date: Mon Apr 13 2026 - 04:06:24 EST
Hi Johan,
Thanks for the review and for pointing that out.
You're right, the correct Fixes tag should be:
Fixes: 89ff3dfac604 ("usb: gadget: f_hid: fix f_hidg lifetime vs cdev")
I'll send a v2 shortly with that fixed and include your Reviewed-by tag.
Reviewed-by: Johan Hovold johan@xxxxxxxxxx
Thanks,
Guangshuo
Johan Hovold <johan@xxxxxxxxxx> 于2026年4月13日周一 15:40写道:
>
> On Mon, Apr 13, 2026 at 12:15:55AM +0800, Guangshuo Li wrote:
> > hidg_alloc() initializes hidg->dev with device_initialize() before
> > calling dev_set_name(). If dev_set_name() fails, the function currently
> > jumps to err_unlock and returns without calling put_device().
> >
> > This leaves the device reference unbalanced and prevents hidg_release()
> > from being called. Calling put_device() here is also safe, since
> > hidg_release() only frees resources owned by hidg.
>
> Good catch.
>
> > Route the dev_set_name() failure path through err_put_device so the
> > device reference is dropped properly.
> >
> > Fixes: 944fe915d00d ("usb: gadget: f_hid: tidy error handling in hidg_alloc")
>
> This isn't the commit that introduced the issue, though. This should be:
>
> Fixes: 89ff3dfac604 ("usb: gadget: f_hid: fix f_hidg lifetime vs cdev")
>
> With that fixed you can add my:
>
> Reviewed-by: Johan Hovold <johan@xxxxxxxxxx>
>
> Johan