diff options
| author | Stephen Warren <[email protected]> | 2015-09-04 22:03:42 -0600 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2015-09-11 17:15:21 -0400 |
| commit | 44bfb43f9afab9b2944bb98bc0d514303f029ff9 (patch) | |
| tree | ae895e7f8c96d96912525305c818cfa49b11f7c3 | |
| parent | 0a04ed86cfaa36d93d55016d0b3dc3f06352a2fe (diff) | |
usb: gadget: don't leak configs when unbinding
By the time g_dnl_unbind() is run, cdev->config has been set to NULL,
so the free() there does nothing, and the config struct is leaked.
Equally, struct usb_gadget contains a linked list of config structs, so
the code should iterate over them all and free each one, rather than
freeing one particular config struct.
composite_unbind() already iterates over the list of config structs, and
unlinks each from the linked list. Fix this loop to free() each struct as
it's unlinked and otherwise forgotten.
Signed-off-by: Stephen Warren <[email protected]>
Acked-by: Lukasz Majewski <[email protected]>
Tested-by: Lukasz Majewski <[email protected]>
| -rw-r--r-- | drivers/usb/gadget/composite.c | 1 | ||||
| -rw-r--r-- | drivers/usb/gadget/g_dnl.c | 2 |
2 files changed, 1 insertions, 2 deletions
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index d96296cd73b..a13b21d0a0f 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -948,6 +948,7 @@ static void composite_unbind(struct usb_gadget *gadget) debug("unbind config '%s'/%p\n", c->label, c); c->unbind(c); } + free(c); } if (composite->unbind) composite->unbind(cdev); diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c index ad89a0d2e67..2fa6da4091e 100644 --- a/drivers/usb/gadget/g_dnl.c +++ b/drivers/usb/gadget/g_dnl.c @@ -93,8 +93,6 @@ static int g_dnl_unbind(struct usb_composite_dev *cdev) { struct usb_gadget *gadget = cdev->gadget; - free(cdev->config); - cdev->config = NULL; debug("%s: calling usb_gadget_disconnect for " "controller '%s'\n", __func__, gadget->name); usb_gadget_disconnect(gadget); |
