devm_kzalloc is device managed and makes error handling and cleanup
simpler. While at it also fixed the return value when platform_device_alloc
failed in probe function.

Cc: Anton Tikhomirov <av.tikhomi...@samsung.com>
Signed-off-by: Sachin Kamat <sachin.ka...@linaro.org>
---
Compile tested on linux-next tree.
---
 drivers/usb/dwc3/dwc3-exynos.c |   13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
index aae5328..db3bd49 100644
--- a/drivers/usb/dwc3/dwc3-exynos.c
+++ b/drivers/usb/dwc3/dwc3-exynos.c
@@ -98,10 +98,10 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
 
        int                     ret = -ENOMEM;
 
-       exynos = kzalloc(sizeof(*exynos), GFP_KERNEL);
+       exynos = devm_kzalloc(&pdev->dev, sizeof(*exynos), GFP_KERNEL);
        if (!exynos) {
                dev_err(&pdev->dev, "not enough memory\n");
-               goto err0;
+               return -ENOMEM;
        }
 
        /*
@@ -117,13 +117,13 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
        ret = dwc3_exynos_register_phys(exynos);
        if (ret) {
                dev_err(&pdev->dev, "couldn't register PHYs\n");
-               goto err1;
+               return ret;
        }
 
        dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
        if (!dwc3) {
                dev_err(&pdev->dev, "couldn't allocate dwc3 device\n");
-               goto err1;
+               return -ENOMEM;
        }
 
        clk = clk_get(&pdev->dev, "usbdrd30");
@@ -164,9 +164,6 @@ err4:
        clk_put(clk);
 err3:
        platform_device_put(dwc3);
-err1:
-       kfree(exynos);
-err0:
        return ret;
 }
 
@@ -181,8 +178,6 @@ static int dwc3_exynos_remove(struct platform_device *pdev)
        clk_disable(exynos->clk);
        clk_put(exynos->clk);
 
-       kfree(exynos);
-
        return 0;
 }
 
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to