drivers/usb/host/ehci-atmel.c: use devm_ functions
authorJulia Lawall <Julia.Lawall@lip6.fr>
Sun, 29 Jul 2012 19:46:05 +0000 (21:46 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Aug 2012 19:01:32 +0000 (12:01 -0700)
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: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/host/ehci-atmel.c

index a47e2cffaaf84a752b709f7e812b85b1dbd4481a..411bb74152ebe2ba3b063fb0e5e3445626d61af1 100644 (file)
@@ -150,31 +150,24 @@ static int __devinit ehci_atmel_drv_probe(struct platform_device *pdev)
        hcd->rsrc_start = res->start;
        hcd->rsrc_len = resource_size(res);
 
-       if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
-                               driver->description)) {
-               dev_dbg(&pdev->dev, "controller already in use\n");
-               retval = -EBUSY;
-               goto fail_request_resource;
-       }
-
-       hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
+       hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
        if (hcd->regs == NULL) {
                dev_dbg(&pdev->dev, "error mapping memory\n");
                retval = -EFAULT;
-               goto fail_ioremap;
+               goto fail_request_resource;
        }
 
-       iclk = clk_get(&pdev->dev, "ehci_clk");
+       iclk = devm_clk_get(&pdev->dev, "ehci_clk");
        if (IS_ERR(iclk)) {
                dev_err(&pdev->dev, "Error getting interface clock\n");
                retval = -ENOENT;
-               goto fail_get_iclk;
+               goto fail_request_resource;
        }
-       fclk = clk_get(&pdev->dev, "uhpck");
+       fclk = devm_clk_get(&pdev->dev, "uhpck");
        if (IS_ERR(fclk)) {
                dev_err(&pdev->dev, "Error getting function clock\n");
                retval = -ENOENT;
-               goto fail_get_fclk;
+               goto fail_request_resource;
        }
 
        atmel_start_ehci(pdev);
@@ -187,13 +180,6 @@ static int __devinit ehci_atmel_drv_probe(struct platform_device *pdev)
 
 fail_add_hcd:
        atmel_stop_ehci(pdev);
-       clk_put(fclk);
-fail_get_fclk:
-       clk_put(iclk);
-fail_get_iclk:
-       iounmap(hcd->regs);
-fail_ioremap:
-       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
 fail_request_resource:
        usb_put_hcd(hcd);
 fail_create_hcd:
@@ -209,13 +195,9 @@ static int __devexit ehci_atmel_drv_remove(struct platform_device *pdev)
 
        ehci_shutdown(hcd);
        usb_remove_hcd(hcd);
-       iounmap(hcd->regs);
-       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
        usb_put_hcd(hcd);
 
        atmel_stop_ehci(pdev);
-       clk_put(fclk);
-       clk_put(iclk);
        fclk = iclk = NULL;
 
        return 0;