Commit af09c060 authored by Julia Lawall's avatar Julia Lawall Committed by Greg Kroah-Hartman

drivers/usb/host/ehci-mxc.c: use devm_ functions

The various devm_ functions allocate memory that is released when a driver
detaches.  This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
Signed-off-by: default avatarJulia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 35b55563
...@@ -121,7 +121,7 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev) ...@@ -121,7 +121,7 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
if (!hcd) if (!hcd)
return -ENOMEM; return -ENOMEM;
priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv) { if (!priv) {
ret = -ENOMEM; ret = -ENOMEM;
goto err_alloc; goto err_alloc;
...@@ -131,34 +131,28 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev) ...@@ -131,34 +131,28 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
if (!res) { if (!res) {
dev_err(dev, "Found HC with no register addr. Check setup!\n"); dev_err(dev, "Found HC with no register addr. Check setup!\n");
ret = -ENODEV; ret = -ENODEV;
goto err_get_resource; goto err_alloc;
} }
hcd->rsrc_start = res->start; hcd->rsrc_start = res->start;
hcd->rsrc_len = resource_size(res); hcd->rsrc_len = resource_size(res);
if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
dev_dbg(dev, "controller already in use\n");
ret = -EBUSY;
goto err_request_mem;
}
hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
if (!hcd->regs) { if (!hcd->regs) {
dev_err(dev, "error mapping memory\n"); dev_err(dev, "error mapping memory\n");
ret = -EFAULT; ret = -EFAULT;
goto err_ioremap; goto err_alloc;
} }
/* enable clocks */ /* enable clocks */
priv->usbclk = clk_get(dev, "ipg"); priv->usbclk = devm_clk_get(&pdev->dev, "ipg");
if (IS_ERR(priv->usbclk)) { if (IS_ERR(priv->usbclk)) {
ret = PTR_ERR(priv->usbclk); ret = PTR_ERR(priv->usbclk);
goto err_clk; goto err_alloc;
} }
clk_prepare_enable(priv->usbclk); clk_prepare_enable(priv->usbclk);
priv->ahbclk = clk_get(dev, "ahb"); priv->ahbclk = devm_clk_get(&pdev->dev, "ahb");
if (IS_ERR(priv->ahbclk)) { if (IS_ERR(priv->ahbclk)) {
ret = PTR_ERR(priv->ahbclk); ret = PTR_ERR(priv->ahbclk);
goto err_clk_ahb; goto err_clk_ahb;
...@@ -166,7 +160,7 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev) ...@@ -166,7 +160,7 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
clk_prepare_enable(priv->ahbclk); clk_prepare_enable(priv->ahbclk);
/* "dr" device has its own clock on i.MX51 */ /* "dr" device has its own clock on i.MX51 */
priv->phyclk = clk_get(dev, "phy"); priv->phyclk = devm_clk_get(&pdev->dev, "phy");
if (IS_ERR(priv->phyclk)) if (IS_ERR(priv->phyclk))
priv->phyclk = NULL; priv->phyclk = NULL;
if (priv->phyclk) if (priv->phyclk)
...@@ -245,23 +239,12 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev) ...@@ -245,23 +239,12 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
if (pdata && pdata->exit) if (pdata && pdata->exit)
pdata->exit(pdev); pdata->exit(pdev);
err_init: err_init:
if (priv->phyclk) { if (priv->phyclk)
clk_disable_unprepare(priv->phyclk); clk_disable_unprepare(priv->phyclk);
clk_put(priv->phyclk);
}
clk_disable_unprepare(priv->ahbclk); clk_disable_unprepare(priv->ahbclk);
clk_put(priv->ahbclk);
err_clk_ahb: err_clk_ahb:
clk_disable_unprepare(priv->usbclk); clk_disable_unprepare(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: err_alloc:
usb_put_hcd(hcd); usb_put_hcd(hcd);
return ret; return ret;
...@@ -280,22 +263,14 @@ static int __exit ehci_mxc_drv_remove(struct platform_device *pdev) ...@@ -280,22 +263,14 @@ static int __exit ehci_mxc_drv_remove(struct platform_device *pdev)
usb_phy_shutdown(pdata->otg); usb_phy_shutdown(pdata->otg);
usb_remove_hcd(hcd); usb_remove_hcd(hcd);
iounmap(hcd->regs);
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
usb_put_hcd(hcd); usb_put_hcd(hcd);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
clk_disable_unprepare(priv->usbclk); clk_disable_unprepare(priv->usbclk);
clk_put(priv->usbclk);
clk_disable_unprepare(priv->ahbclk); clk_disable_unprepare(priv->ahbclk);
clk_put(priv->ahbclk);
if (priv->phyclk) { if (priv->phyclk)
clk_disable_unprepare(priv->phyclk); clk_disable_unprepare(priv->phyclk);
clk_put(priv->phyclk);
}
kfree(priv);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment