[ 253/262] usb: chipidea: cleanup dma_pool if udc_start() fails
From: Greg Kroah-Hartman
Date: Fri Sep 28 2012 - 15:07:30 EST
From: Greg KH <gregkh@xxxxxxxxxxxxxxxxxxx>
3.5-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>
commit ad6b1b97fe8504957d017cd6e4168cac8903d3f3 upstream.
If udc_start() fails the qh_pool dma-pool cannot be closed because
it's still in use. This patch factors out the dma_pool_free() loop
into destroy_eps() and calls it in the error path of udc_start(),
too.
Reviewed-by: Richard Zhao <richard.zhao@xxxxxxxxxxxxx>
Signed-off-by: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>
Signed-off-by: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
[mkl: backport to v3.5]
Signed-off-by: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>
---
drivers/usb/chipidea/udc.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -1500,6 +1500,17 @@ static int init_eps(struct ci13xxx *udc)
return retval;
}
+static void destroy_eps(struct ci13xxx *udc)
+{
+ int i;
+
+ for (i = 0; i < udc->hw_ep_max; i++) {
+ struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i];
+
+ dma_pool_free(udc->qh_pool, mEp->qh.ptr, mEp->qh.dma);
+ }
+}
+
/**
* ci13xxx_start: register a gadget driver
* @gadget: our gadget
@@ -1709,7 +1720,7 @@ static int udc_start(struct ci13xxx *udc
if (udc->udc_driver->flags & CI13XXX_REQUIRE_TRANSCEIVER) {
if (udc->transceiver == NULL) {
retval = -ENODEV;
- goto free_pools;
+ goto destroy_eps;
}
}
@@ -1759,6 +1770,8 @@ unreg_device:
put_transceiver:
if (udc->transceiver)
usb_put_transceiver(udc->transceiver);
+destroy_eps:
+ destroy_eps(udc);
free_pools:
dma_pool_destroy(udc->td_pool);
free_qh_pool:
@@ -1773,18 +1786,12 @@ free_qh_pool:
*/
static void udc_stop(struct ci13xxx *udc)
{
- int i;
-
if (udc == NULL)
return;
usb_del_gadget_udc(&udc->gadget);
- for (i = 0; i < udc->hw_ep_max; i++) {
- struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i];
-
- dma_pool_free(udc->qh_pool, mEp->qh.ptr, mEp->qh.dma);
- }
+ destroy_eps(udc);
dma_pool_destroy(udc->td_pool);
dma_pool_destroy(udc->qh_pool);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/