]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
usb: chipidea: cleanup dma_pool if udc_start() fails
authorMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 12 Sep 2012 11:58:03 +0000 (14:58 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 2 Oct 2012 17:40:02 +0000 (10:40 -0700)
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@freescale.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[mkl: backport to v3.5]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/usb/chipidea/udc.c

index 90d9f43da325a75b2decce0412916bc24a6a5f19..ea271d717dba3db7a39309118be15fdb5a90f94f 100644 (file)
@@ -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);