summaryrefslogtreecommitdiffstats
path: root/drivers/usb/dwc3/dwc3-omap.c
diff options
context:
space:
mode:
authorChanho Park <chanho61.park@samsung.com>2012-02-15 18:27:55 +0900
committerFelipe Balbi <balbi@ti.com>2012-03-02 12:11:59 +0200
commit802ca85067e11cdeddeb34ef53de03e5a7d509da (patch)
treeff55f46e2e1586570e9e7b4a98b3c2c979c75c1f /drivers/usb/dwc3/dwc3-omap.c
parentd28a9689c93195d39f91f35a9519876688605b65 (diff)
downloadlinux-802ca85067e11cdeddeb34ef53de03e5a7d509da.tar.bz2
usb: dwc3: use devm_xxx functions
This patch enables to use devm_xxx functions during probing driver. The devm_xxx series functions are able to release resource when the driver is detatched. We can remove several codes to release resources in the probe function. Signed-off-by: Chanho Park <chanho61.park@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/dwc3/dwc3-omap.c')
-rw-r--r--drivers/usb/dwc3/dwc3-omap.c85
1 files changed, 33 insertions, 52 deletions
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index 64e29c31df22..f2e6b050dab3 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -203,6 +203,7 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
struct platform_device *dwc3;
struct dwc3_omap *omap;
struct resource *res;
+ struct device *dev = &pdev->dev;
int devid;
int size;
@@ -215,59 +216,57 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
void __iomem *base;
void *context;
- omap = kzalloc(sizeof(*omap), GFP_KERNEL);
+ omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
if (!omap) {
- dev_err(&pdev->dev, "not enough memory\n");
- goto err0;
+ dev_err(dev, "not enough memory\n");
+ return -ENOMEM;
}
platform_set_drvdata(pdev, omap);
irq = platform_get_irq(pdev, 1);
if (irq < 0) {
- dev_err(&pdev->dev, "missing IRQ resource\n");
- ret = -EINVAL;
- goto err1;
+ dev_err(dev, "missing IRQ resource\n");
+ return -EINVAL;
}
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
if (!res) {
- dev_err(&pdev->dev, "missing memory base resource\n");
- ret = -EINVAL;
- goto err1;
+ dev_err(dev, "missing memory base resource\n");
+ return -EINVAL;
}
- base = ioremap_nocache(res->start, resource_size(res));
+ base = devm_ioremap_nocache(dev, res->start, resource_size(res));
if (!base) {
- dev_err(&pdev->dev, "ioremap failed\n");
- goto err1;
+ dev_err(dev, "ioremap failed\n");
+ return -ENOMEM;
}
devid = dwc3_get_device_id();
if (devid < 0)
- goto err2;
+ return -ENODEV;
dwc3 = platform_device_alloc("dwc3", devid);
if (!dwc3) {
- dev_err(&pdev->dev, "couldn't allocate dwc3 device\n");
- goto err3;
+ dev_err(dev, "couldn't allocate dwc3 device\n");
+ goto err1;
}
- context = kzalloc(resource_size(res), GFP_KERNEL);
+ context = devm_kzalloc(dev, resource_size(res), GFP_KERNEL);
if (!context) {
- dev_err(&pdev->dev, "couldn't allocate dwc3 context memory\n");
- goto err4;
+ dev_err(dev, "couldn't allocate dwc3 context memory\n");
+ goto err2;
}
spin_lock_init(&omap->lock);
- 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;
omap->resource_size = resource_size(res);
omap->context = context;
- omap->dev = &pdev->dev;
+ omap->dev = dev;
omap->irq = irq;
omap->base = base;
omap->dwc3 = dwc3;
@@ -279,7 +278,7 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
reg |= *utmi_mode;
} else {
if (!pdata) {
- dev_dbg(&pdev->dev, "missing platform data\n");
+ dev_dbg(dev, "missing platform data\n");
} else {
switch (pdata->utmi_mode) {
case DWC3_OMAP_UTMI_MODE_SW:
@@ -289,7 +288,7 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
break;
default:
- dev_dbg(&pdev->dev, "UNKNOWN utmi mode %d\n",
+ dev_dbg(dev, "UNKNOWN utmi mode %d\n",
pdata->utmi_mode);
}
}
@@ -310,12 +309,12 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
dwc3_writel(omap->base, USBOTGSS_SYSCONFIG, reg);
- ret = request_irq(omap->irq, dwc3_omap_interrupt, 0,
+ ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0,
"dwc3-omap", omap);
if (ret) {
- dev_err(&pdev->dev, "failed to request IRQ #%d --> %d\n",
+ dev_err(dev, "failed to request IRQ #%d --> %d\n",
omap->irq, ret);
- goto err5;
+ goto err2;
}
/* enable all IRQs */
@@ -337,37 +336,24 @@ static int __devinit dwc3_omap_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 err6;
+ dev_err(dev, "couldn't add resources to dwc3 device\n");
+ goto err2;
}
ret = platform_device_add(dwc3);
if (ret) {
- dev_err(&pdev->dev, "failed to register dwc3 device\n");
- goto err6;
+ dev_err(dev, "failed to register dwc3 device\n");
+ goto err2;
}
return 0;
-err6:
- free_irq(omap->irq, omap);
-
-err5:
- kfree(omap->context);
-
-err4:
- platform_device_put(dwc3);
-
-err3:
- dwc3_put_device_id(devid);
-
err2:
- iounmap(base);
+ platform_device_put(dwc3);
err1:
- kfree(omap);
+ dwc3_put_device_id(devid);
-err0:
return ret;
}
@@ -378,11 +364,6 @@ static int __devexit dwc3_omap_remove(struct platform_device *pdev)
platform_device_unregister(omap->dwc3);
dwc3_put_device_id(omap->dwc3->id);
- free_irq(omap->irq, omap);
- iounmap(omap->base);
-
- kfree(omap->context);
- kfree(omap);
return 0;
}