From: Marc Kleine-Budde Date: Wed, 12 Sep 2012 11:58:03 +0000 (+0300) Subject: usb: chipidea: cleanup dma_pool if udc_start() fails X-Git-Tag: v3.5.5~11 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=6b8b3d7b9720603433f7ab99a114a2f3e1453c71;p=karo-tx-linux.git usb: chipidea: cleanup dma_pool if udc_start() fails 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 Signed-off-by: Marc Kleine-Budde Signed-off-by: Alexander Shishkin Signed-off-by: Greg Kroah-Hartman [mkl: backport to v3.5] Signed-off-by: Marc Kleine-Budde --- diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 90d9f43da325..ea271d717dba 100644 --- 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);