The interrupt handler can access endpoint state and the DMA descriptor pool. However, the IRQ is currently requested before these resources are allocated, complicating the probe error handling.
Move request_irq() after struct_udc_setup() and dma_pool_create() so that the resources can be released in reverse acquisition order. Signed-off-by: Wanhui Fu <[email protected]> --- drivers/usb/gadget/udc/fsl_udc_core.c | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/usb/gadget/udc/fsl_udc_core.c b/drivers/usb/gadget/udc/fsl_udc_core.c index bf30c64e4983..398a4c19e86d 100644 --- a/drivers/usb/gadget/udc/fsl_udc_core.c +++ b/drivers/usb/gadget/udc/fsl_udc_core.c @@ -2451,22 +2451,14 @@ static int fsl_udc_probe(struct platform_device *pdev) } udc_controller->irq = ret; - ret = request_irq(udc_controller->irq, fsl_udc_irq, IRQF_SHARED, - driver_name, udc_controller); - if (ret != 0) { - dev_err(&pdev->dev, "cannot request irq %d err %d\n", - udc_controller->irq, ret); - goto err_exit; - } - /* Initialize the udc structure including QH member and other member */ if (struct_udc_setup(udc_controller, pdev)) { dev_err(&pdev->dev, "Can't initialize udc data structure\n"); ret = -ENOMEM; - goto err_free_irq; + goto err_exit; } - /* Allocate the pool before programming the queue head address. */ + /* Acquire the pool and IRQ before programming the queue head address. */ udc_controller->td_pool = dma_pool_create("udc_td", &pdev->dev, sizeof(struct ep_td_struct), DTD_ALIGNMENT, @@ -2476,6 +2468,14 @@ static int fsl_udc_probe(struct platform_device *pdev) goto err_free_setup; } + ret = request_irq(udc_controller->irq, fsl_udc_irq, IRQF_SHARED, + driver_name, udc_controller); + if (ret) { + dev_err(&pdev->dev, "cannot request irq %d err %d\n", + udc_controller->irq, ret); + goto err_destroy_pool; + } + if (IS_ERR_OR_NULL(udc_controller->transceiver)) { /* initialize usb hw reg except for regs for EP, * leave usbintr reg untouched */ @@ -2518,18 +2518,17 @@ static int fsl_udc_probe(struct platform_device *pdev) ret = usb_add_gadget(&udc_controller->gadget); if (ret) - goto err_free_setup; + goto err_free_irq; create_proc_file(); return 0; -err_free_setup: +err_free_irq: free_irq(udc_controller->irq, udc_controller); +err_destroy_pool: dma_pool_destroy(udc_controller->td_pool); +err_free_setup: struct_udc_cleanup(udc_controller); - goto err_exit; -err_free_irq: - free_irq(udc_controller->irq, udc_controller); err_exit: if (pdata->exit) pdata->exit(pdev); -- 2.25.1
