• Alan Stern's avatar
    USB: Gadget core: fix inconsistency in the interface tousb_add_gadget_udc_release() · afd7fd81
    Alan Stern authored
    The usb_add_gadget_udc_release() routine in the USB gadget core will
    sometimes but not always call the gadget's release function when an
    error occurs.  More specifically, if the struct usb_udc allocation
    fails then the release function is not called, and for other errors it
    is.
    
    As a result, users of this routine cannot know whether they need to
    deallocate the memory containing the gadget structure following an
    error.  This leads to unavoidable memory leaks or double frees.
    
    This patch fixes the problem by splitting the existing
    device_register() call into device_initialize() and device_add(), and
    doing the udc allocation in between.  That way, even if the allocation
    fails it is still possible to call device_del(), and so the release
    function will be always called following an error.
    Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
    Reported-by: default avatarAlexey Khoroshilov <khoroshilov@ispras.ru>
    Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
    afd7fd81
core.c 43.1 KB