The devm_ functions allocate memory that is released when a driver detaches. This makes the code smaller and a bit simpler. Cc: Anton Tikhomirov <av.tikhomirov@xxxxxxxxxxx> Signed-off-by: Jingoo Han <jg1.han@xxxxxxxxxxx> --- drivers/usb/dwc3/dwc3-exynos.c | 59 +++++++++++++++++++--------------------- 1 files changed, 28 insertions(+), 31 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c index ca65978..d5e2c62 100644 --- a/drivers/usb/dwc3/dwc3-exynos.c +++ b/drivers/usb/dwc3/dwc3-exynos.c @@ -93,55 +93,56 @@ static int __devinit dwc3_exynos_probe(struct platform_device *pdev) struct platform_device *dwc3; struct dwc3_exynos *exynos; struct clk *clk; + struct device *dev = &pdev->dev; int devid; int ret = -ENOMEM; - exynos = kzalloc(sizeof(*exynos), GFP_KERNEL); + exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); if (!exynos) { - dev_err(&pdev->dev, "not enough memory\n"); - goto err0; + dev_err(dev, "not enough memory\n"); + return -ENOMEM; } platform_set_drvdata(pdev, exynos); devid = dwc3_get_device_id(); if (devid < 0) - goto err1; + return -ENODEV; ret = dwc3_exynos_register_phys(exynos); if (ret) { - dev_err(&pdev->dev, "couldn't register PHYs\n"); - goto err1; + dev_err(dev, "couldn't register PHYs\n"); + return ret; } dwc3 = platform_device_alloc("dwc3", devid); if (!dwc3) { - dev_err(&pdev->dev, "couldn't allocate dwc3 device\n"); - goto err2; + dev_err(dev, "couldn't allocate dwc3 device\n"); + goto err1; } - clk = clk_get(&pdev->dev, "usbdrd30"); + clk = devm_clk_get(dev, "usbdrd30"); if (IS_ERR(clk)) { - dev_err(&pdev->dev, "couldn't get clock\n"); + dev_err(dev, "couldn't get clock\n"); ret = -EINVAL; - goto err3; + goto err2; } - dma_set_coherent_mask(&dwc3->dev, pdev->dev.coherent_dma_mask); + dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask); - dwc3->dev.parent = &pdev->dev; - dwc3->dev.dma_mask = pdev->dev.dma_mask; - dwc3->dev.dma_parms = pdev->dev.dma_parms; + dwc3->dev.parent = dev; + dwc3->dev.dma_mask = dev->dma_mask; + dwc3->dev.dma_parms = dev->dma_parms; exynos->dwc3 = dwc3; - exynos->dev = &pdev->dev; + exynos->dev = dev; exynos->clk = clk; clk_enable(exynos->clk); /* PHY initialization */ if (!pdata) { - dev_dbg(&pdev->dev, "missing platform data\n"); + dev_dbg(dev, "missing platform data\n"); } else { if (pdata->phy_init) pdata->phy_init(pdev, pdata->phy_type); @@ -150,31 +151,30 @@ static int __devinit dwc3_exynos_probe(struct platform_device *pdev) ret = platform_device_add_resources(dwc3, pdev->resource, pdev->num_resources); if (ret) { - dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n"); - goto err4; + dev_err(dev, "couldn't add resources to dwc3 device\n"); + goto err3; } ret = platform_device_add(dwc3); if (ret) { - dev_err(&pdev->dev, "failed to register dwc3 device\n"); - goto err4; + dev_err(dev, "failed to register dwc3 device\n"); + goto err3; } return 0; -err4: +err3: if (pdata && pdata->phy_exit) pdata->phy_exit(pdev, pdata->phy_type); clk_disable(clk); - clk_put(clk); -err3: - platform_device_put(dwc3); + err2: - dwc3_put_device_id(devid); + platform_device_put(dwc3); + err1: - kfree(exynos); -err0: + dwc3_put_device_id(devid); + return ret; } @@ -193,9 +193,6 @@ static int __devexit dwc3_exynos_remove(struct platform_device *pdev) pdata->phy_exit(pdev, pdata->phy_type); clk_disable(exynos->clk); - clk_put(exynos->clk); - - kfree(exynos); 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