Use devm functions to simplify error handling and also make the code a bit smaller. Signed-off-by: Fabio Estevam <fabio.estevam@xxxxxxxxxxxxx> --- drivers/usb/host/ehci-mxc.c | 33 +++++++++------------------------ 1 files changed, 9 insertions(+), 24 deletions(-) diff --git a/drivers/usb/host/ehci-mxc.c b/drivers/usb/host/ehci-mxc.c index a797d51..b560765 100644 --- a/drivers/usb/host/ehci-mxc.c +++ b/drivers/usb/host/ehci-mxc.c @@ -136,33 +136,29 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev) if (!hcd) return -ENOMEM; - priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) { - ret = -ENOMEM; - goto err_alloc; - } + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(dev, "Found HC with no register addr. Check setup!\n"); - ret = -ENODEV; - goto err_get_resource; + return -ENODEV; } hcd->rsrc_start = res->start; hcd->rsrc_len = resource_size(res); - if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { + if (!devm_request_mem_region(dev, hcd->rsrc_start, hcd->rsrc_len, + hcd_name)) { dev_dbg(dev, "controller already in use\n"); - ret = -EBUSY; - goto err_request_mem; + return -EBUSY; } - hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); + hcd->regs = devm_ioremap(dev, hcd->rsrc_start, hcd->rsrc_len); if (!hcd->regs) { dev_err(dev, "error mapping memory\n"); - ret = -EFAULT; - goto err_ioremap; + return -EFAULT; } /* enable clocks */ @@ -278,13 +274,6 @@ err_clk_ahb: clk_disable(priv->usbclk); clk_put(priv->usbclk); err_clk: - iounmap(hcd->regs); -err_ioremap: - release_mem_region(hcd->rsrc_start, hcd->rsrc_len); -err_request_mem: -err_get_resource: - kfree(priv); -err_alloc: usb_put_hcd(hcd); return ret; } @@ -302,8 +291,6 @@ static int __exit ehci_mxc_drv_remove(struct platform_device *pdev) usb_phy_shutdown(pdata->otg); usb_remove_hcd(hcd); - iounmap(hcd->regs); - release_mem_region(hcd->rsrc_start, hcd->rsrc_len); usb_put_hcd(hcd); platform_set_drvdata(pdev, NULL); @@ -318,8 +305,6 @@ static int __exit ehci_mxc_drv_remove(struct platform_device *pdev) clk_put(priv->phy1clk); } - kfree(priv); - return 0; } -- 1.7.1 -- 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