]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
usb: gadget: net2280: Fix double free in probe error path
authorGuangshuo Li <lgs201920130244@gmail.com>
Mon, 27 Apr 2026 15:36:51 +0000 (23:36 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 22 May 2026 08:35:22 +0000 (10:35 +0200)
usb_initialize_gadget() installs gadget_release() as the release
callback for the embedded gadget device.  The struct net2280 instance is
therefore released through gadget_release() when the gadget device's last
reference is dropped.

The probe error path calls net2280_remove(), which tears down the
partially initialized device and drops the gadget reference with
usb_put_gadget().  Calling kfree(dev) afterwards can free the same object
again.

Drop the explicit kfree() and let the gadget device release callback
handle the final free.  This issue was found by a static analysis tool
I am developing.

Fixes: f770fbec4165 ("USB: UDC: net2280: Fix memory leaks")
Cc: stable <stable@kernel.org>
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://patch.msgid.link/20260427153651.337846-1-lgs201920130244@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/udc/net2280.c

index d02765bd49ce46549613e7ace4ff00e404bc97e7..7c5f30cfd24d842139f16eb900e718bd9e0247df 100644 (file)
@@ -3790,10 +3790,8 @@ static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        return 0;
 
 done:
-       if (dev) {
+       if (dev)
                net2280_remove(pdev);
-               kfree(dev);
-       }
        return retval;
 }