Use devm_* helpers in the probe function to simplify the error path and the remove path. Signed-off-by: Robert Jarzmik <robert.jarzmik@xxxxxxx> --- drivers/usb/gadget/pxa27x_udc.c | 51 +++++++++++------------------------------ 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c index 6236848..f6843a8 100644 --- a/drivers/usb/gadget/pxa27x_udc.c +++ b/drivers/usb/gadget/pxa27x_udc.c @@ -2478,8 +2478,9 @@ static int pxa_udc_probe(struct platform_device *pdev) pxa_udc_probe_pdata(pdev, udc); regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); + udc->regs = devm_request_and_ioremap(&pdev->dev, regs); if (!regs) - return -ENXIO; + return -EADDRNOTAVAIL; udc->irq = platform_get_irq(pdev, 0); if (udc->irq < 0) return udc->irq; @@ -2488,7 +2489,8 @@ static int pxa_udc_probe(struct platform_device *pdev) udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); if (gpio_is_valid(udc->gpio_pullup)) { - retval = gpio_request(udc->gpio_pullup, "USB D+ pullup"); + retval = devm_gpio_request(&pdev->dev, + udc->gpio_pullup, "USB D+ pullup"); if (retval == 0) gpio_direction_output(udc->gpio_pullup, udc->gpio_pullup_inverted); @@ -2499,21 +2501,13 @@ static int pxa_udc_probe(struct platform_device *pdev) return retval; } - udc->clk = clk_get(&pdev->dev, NULL); - if (IS_ERR(udc->clk)) { - retval = PTR_ERR(udc->clk); - goto err_clk; - } + udc->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(udc->clk)) + return PTR_ERR(udc->clk); + retval = clk_prepare(udc->clk); if (retval) - goto err_clk_prepare; - - retval = -ENOMEM; - udc->regs = ioremap(regs->start, resource_size(regs)); - if (!udc->regs) { - dev_err(&pdev->dev, "Unable to map UDC I/O memory\n"); - goto err_map; - } + return retval; udc->vbus_sensed = 0; @@ -2523,34 +2517,23 @@ static int pxa_udc_probe(struct platform_device *pdev) pxa_eps_setup(udc); /* irq setup after old hardware state is cleaned up */ - retval = request_irq(udc->irq, pxa_udc_irq, - IRQF_SHARED, driver_name, udc); + retval = devm_request_irq(&pdev->dev, udc->irq, pxa_udc_irq, + IRQF_SHARED, driver_name, udc); if (retval != 0) { dev_err(udc->dev, "%s: can't get irq %i, err %d\n", driver_name, udc->irq, retval); - goto err_irq; + goto err; } retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); if (retval) - goto err_add_udc; + goto err; pxa_init_debugfs(udc); return 0; -err_add_udc: - free_irq(udc->irq, udc); -err_irq: - iounmap(udc->regs); -err_map: - clk_unprepare(udc->clk); -err_clk_prepare: - clk_put(udc->clk); - udc->clk = NULL; -err_clk: - if (gpio_is_valid(udc->gpio_pullup)) - gpio_free(udc->gpio_pullup); +err: return retval; } @@ -2561,22 +2544,16 @@ err_clk: static int pxa_udc_remove(struct platform_device *_dev) { struct pxa_udc *udc = platform_get_drvdata(_dev); - int gpio = udc->mach->gpio_pullup; usb_del_gadget_udc(&udc->gadget); usb_gadget_unregister_driver(udc->driver); - free_irq(udc->irq, udc); pxa_cleanup_debugfs(udc); - if (gpio_is_valid(gpio)) - gpio_free(gpio); usb_put_phy(udc->transceiver); udc->transceiver = NULL; the_controller = NULL; clk_unprepare(udc->clk); - clk_put(udc->clk); - iounmap(udc->regs); return 0; } -- 2.0.0.rc2 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html