Re: [PATCH v2] usb: gadget: f_hid: fix device reference leak in hidg_alloc()

From: Greg Kroah-Hartman

Date: Mon Apr 13 2026 - 06:46:32 EST


On Mon, Apr 13, 2026 at 04:12:37PM +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.
>
> Route the dev_set_name() failure path through err_put_device so the
> device reference is dropped properly.
>
> Fixes: 89ff3dfac604 ("usb: gadget: f_hid: fix f_hidg lifetime vs cdev")
> Cc: stable@xxxxxxxxxxxxxxx
> Reviewed-by: Johan Hovold <johan@xxxxxxxxxx>
> Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
> ---
> v2:
> - correct Fixes tag to 89ff3dfac604
> - add Reviewed-by from Johan Hovold

As you are using a tool to find/fix these things, you HAVE to mention
that as per our documentation. Please go and read that and then
resubmit all of thes patches that need that attribution added.

thanks,

greg k-h