提交 802ca850 编写于 作者: C Chanho Park 提交者: Felipe Balbi

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: NChanho Park <chanho61.park@samsung.com>
Signed-off-by: NKyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: NFelipe Balbi <balbi@ti.com>
上级 d28a9689
...@@ -408,6 +408,7 @@ static int __devinit dwc3_probe(struct platform_device *pdev) ...@@ -408,6 +408,7 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
struct device_node *node = pdev->dev.of_node; struct device_node *node = pdev->dev.of_node;
struct resource *res; struct resource *res;
struct dwc3 *dwc; struct dwc3 *dwc;
struct device *dev = &pdev->dev;
int ret = -ENOMEM; int ret = -ENOMEM;
int irq; int irq;
...@@ -417,39 +418,39 @@ static int __devinit dwc3_probe(struct platform_device *pdev) ...@@ -417,39 +418,39 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
u8 mode; u8 mode;
mem = kzalloc(sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
if (!mem) { if (!mem) {
dev_err(&pdev->dev, "not enough memory\n"); dev_err(dev, "not enough memory\n");
goto err0; return -ENOMEM;
} }
dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
dwc->mem = mem; dwc->mem = mem;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) { if (!res) {
dev_err(&pdev->dev, "missing resource\n"); dev_err(dev, "missing resource\n");
goto err1; return -ENODEV;
} }
dwc->res = res; dwc->res = res;
res = request_mem_region(res->start, resource_size(res), res = devm_request_mem_region(dev, res->start, resource_size(res),
dev_name(&pdev->dev)); dev_name(dev));
if (!res) { if (!res) {
dev_err(&pdev->dev, "can't request mem region\n"); dev_err(dev, "can't request mem region\n");
goto err1; return -ENOMEM;
} }
regs = ioremap(res->start, resource_size(res)); regs = devm_ioremap(dev, res->start, resource_size(res));
if (!regs) { if (!regs) {
dev_err(&pdev->dev, "ioremap failed\n"); dev_err(dev, "ioremap failed\n");
goto err2; return -ENOMEM;
} }
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) { if (irq < 0) {
dev_err(&pdev->dev, "missing IRQ\n"); dev_err(dev, "missing IRQ\n");
goto err3; return -ENODEV;
} }
spin_lock_init(&dwc->lock); spin_lock_init(&dwc->lock);
...@@ -457,7 +458,7 @@ static int __devinit dwc3_probe(struct platform_device *pdev) ...@@ -457,7 +458,7 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
dwc->regs = regs; dwc->regs = regs;
dwc->regs_size = resource_size(res); dwc->regs_size = resource_size(res);
dwc->dev = &pdev->dev; dwc->dev = dev;
dwc->irq = irq; dwc->irq = irq;
if (!strncmp("super", maximum_speed, 5)) if (!strncmp("super", maximum_speed, 5))
...@@ -474,14 +475,14 @@ static int __devinit dwc3_probe(struct platform_device *pdev) ...@@ -474,14 +475,14 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
if (of_get_property(node, "tx-fifo-resize", NULL)) if (of_get_property(node, "tx-fifo-resize", NULL))
dwc->needs_fifo_resize = true; dwc->needs_fifo_resize = true;
pm_runtime_enable(&pdev->dev); pm_runtime_enable(dev);
pm_runtime_get_sync(&pdev->dev); pm_runtime_get_sync(dev);
pm_runtime_forbid(&pdev->dev); pm_runtime_forbid(dev);
ret = dwc3_core_init(dwc); ret = dwc3_core_init(dwc);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to initialize core\n"); dev_err(dev, "failed to initialize core\n");
goto err3; return ret;
} }
mode = DWC3_MODE(dwc->hwparams.hwparams0); mode = DWC3_MODE(dwc->hwparams.hwparams0);
...@@ -491,49 +492,49 @@ static int __devinit dwc3_probe(struct platform_device *pdev) ...@@ -491,49 +492,49 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
ret = dwc3_gadget_init(dwc); ret = dwc3_gadget_init(dwc);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to initialize gadget\n"); dev_err(dev, "failed to initialize gadget\n");
goto err4; goto err1;
} }
break; break;
case DWC3_MODE_HOST: case DWC3_MODE_HOST:
dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
ret = dwc3_host_init(dwc); ret = dwc3_host_init(dwc);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to initialize host\n"); dev_err(dev, "failed to initialize host\n");
goto err4; goto err1;
} }
break; break;
case DWC3_MODE_DRD: case DWC3_MODE_DRD:
dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
ret = dwc3_host_init(dwc); ret = dwc3_host_init(dwc);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to initialize host\n"); dev_err(dev, "failed to initialize host\n");
goto err4; goto err1;
} }
ret = dwc3_gadget_init(dwc); ret = dwc3_gadget_init(dwc);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to initialize gadget\n"); dev_err(dev, "failed to initialize gadget\n");
goto err4; goto err1;
} }
break; break;
default: default:
dev_err(&pdev->dev, "Unsupported mode of operation %d\n", mode); dev_err(dev, "Unsupported mode of operation %d\n", mode);
goto err4; goto err1;
} }
dwc->mode = mode; dwc->mode = mode;
ret = dwc3_debugfs_init(dwc); ret = dwc3_debugfs_init(dwc);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to initialize debugfs\n"); dev_err(dev, "failed to initialize debugfs\n");
goto err5; goto err2;
} }
pm_runtime_allow(&pdev->dev); pm_runtime_allow(dev);
return 0; return 0;
err5: err2:
switch (mode) { switch (mode) {
case DWC3_MODE_DEVICE: case DWC3_MODE_DEVICE:
dwc3_gadget_exit(dwc); dwc3_gadget_exit(dwc);
...@@ -550,19 +551,9 @@ static int __devinit dwc3_probe(struct platform_device *pdev) ...@@ -550,19 +551,9 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
break; break;
} }
err4:
dwc3_core_exit(dwc);
err3:
iounmap(regs);
err2:
release_mem_region(res->start, resource_size(res));
err1: err1:
kfree(dwc->mem); dwc3_core_exit(dwc);
err0:
return ret; return ret;
} }
...@@ -595,9 +586,6 @@ static int __devexit dwc3_remove(struct platform_device *pdev) ...@@ -595,9 +586,6 @@ static int __devexit dwc3_remove(struct platform_device *pdev)
} }
dwc3_core_exit(dwc); dwc3_core_exit(dwc);
release_mem_region(res->start, resource_size(res));
iounmap(dwc->regs);
kfree(dwc->mem);
return 0; return 0;
} }
......
...@@ -203,6 +203,7 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev) ...@@ -203,6 +203,7 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
struct platform_device *dwc3; struct platform_device *dwc3;
struct dwc3_omap *omap; struct dwc3_omap *omap;
struct resource *res; struct resource *res;
struct device *dev = &pdev->dev;
int devid; int devid;
int size; int size;
...@@ -215,59 +216,57 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev) ...@@ -215,59 +216,57 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
void __iomem *base; void __iomem *base;
void *context; void *context;
omap = kzalloc(sizeof(*omap), GFP_KERNEL); omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
if (!omap) { if (!omap) {
dev_err(&pdev->dev, "not enough memory\n"); dev_err(dev, "not enough memory\n");
goto err0; return -ENOMEM;
} }
platform_set_drvdata(pdev, omap); platform_set_drvdata(pdev, omap);
irq = platform_get_irq(pdev, 1); irq = platform_get_irq(pdev, 1);
if (irq < 0) { if (irq < 0) {
dev_err(&pdev->dev, "missing IRQ resource\n"); dev_err(dev, "missing IRQ resource\n");
ret = -EINVAL; return -EINVAL;
goto err1;
} }
res = platform_get_resource(pdev, IORESOURCE_MEM, 1); res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
if (!res) { if (!res) {
dev_err(&pdev->dev, "missing memory base resource\n"); dev_err(dev, "missing memory base resource\n");
ret = -EINVAL; return -EINVAL;
goto err1;
} }
base = ioremap_nocache(res->start, resource_size(res)); base = devm_ioremap_nocache(dev, res->start, resource_size(res));
if (!base) { if (!base) {
dev_err(&pdev->dev, "ioremap failed\n"); dev_err(dev, "ioremap failed\n");
goto err1; return -ENOMEM;
} }
devid = dwc3_get_device_id(); devid = dwc3_get_device_id();
if (devid < 0) if (devid < 0)
goto err2; return -ENODEV;
dwc3 = platform_device_alloc("dwc3", devid); dwc3 = platform_device_alloc("dwc3", devid);
if (!dwc3) { if (!dwc3) {
dev_err(&pdev->dev, "couldn't allocate dwc3 device\n"); dev_err(dev, "couldn't allocate dwc3 device\n");
goto err3; goto err1;
} }
context = kzalloc(resource_size(res), GFP_KERNEL); context = devm_kzalloc(dev, resource_size(res), GFP_KERNEL);
if (!context) { if (!context) {
dev_err(&pdev->dev, "couldn't allocate dwc3 context memory\n"); dev_err(dev, "couldn't allocate dwc3 context memory\n");
goto err4; goto err2;
} }
spin_lock_init(&omap->lock); 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.parent = dev;
dwc3->dev.dma_mask = pdev->dev.dma_mask; dwc3->dev.dma_mask = dev->dma_mask;
dwc3->dev.dma_parms = pdev->dev.dma_parms; dwc3->dev.dma_parms = dev->dma_parms;
omap->resource_size = resource_size(res); omap->resource_size = resource_size(res);
omap->context = context; omap->context = context;
omap->dev = &pdev->dev; omap->dev = dev;
omap->irq = irq; omap->irq = irq;
omap->base = base; omap->base = base;
omap->dwc3 = dwc3; omap->dwc3 = dwc3;
...@@ -279,7 +278,7 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev) ...@@ -279,7 +278,7 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
reg |= *utmi_mode; reg |= *utmi_mode;
} else { } else {
if (!pdata) { if (!pdata) {
dev_dbg(&pdev->dev, "missing platform data\n"); dev_dbg(dev, "missing platform data\n");
} else { } else {
switch (pdata->utmi_mode) { switch (pdata->utmi_mode) {
case DWC3_OMAP_UTMI_MODE_SW: case DWC3_OMAP_UTMI_MODE_SW:
...@@ -289,7 +288,7 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev) ...@@ -289,7 +288,7 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE; reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
break; break;
default: default:
dev_dbg(&pdev->dev, "UNKNOWN utmi mode %d\n", dev_dbg(dev, "UNKNOWN utmi mode %d\n",
pdata->utmi_mode); pdata->utmi_mode);
} }
} }
...@@ -310,12 +309,12 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev) ...@@ -310,12 +309,12 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
dwc3_writel(omap->base, USBOTGSS_SYSCONFIG, reg); 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); "dwc3-omap", omap);
if (ret) { 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); omap->irq, ret);
goto err5; goto err2;
} }
/* enable all IRQs */ /* enable all IRQs */
...@@ -337,37 +336,24 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev) ...@@ -337,37 +336,24 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
ret = platform_device_add_resources(dwc3, pdev->resource, ret = platform_device_add_resources(dwc3, pdev->resource,
pdev->num_resources); pdev->num_resources);
if (ret) { if (ret) {
dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n"); dev_err(dev, "couldn't add resources to dwc3 device\n");
goto err6; goto err2;
} }
ret = platform_device_add(dwc3); ret = platform_device_add(dwc3);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to register dwc3 device\n"); dev_err(dev, "failed to register dwc3 device\n");
goto err6; goto err2;
} }
return 0; return 0;
err6:
free_irq(omap->irq, omap);
err5:
kfree(omap->context);
err4:
platform_device_put(dwc3);
err3:
dwc3_put_device_id(devid);
err2: err2:
iounmap(base); platform_device_put(dwc3);
err1: err1:
kfree(omap); dwc3_put_device_id(devid);
err0:
return ret; return ret;
} }
...@@ -378,11 +364,6 @@ static int __devexit dwc3_omap_remove(struct platform_device *pdev) ...@@ -378,11 +364,6 @@ static int __devexit dwc3_omap_remove(struct platform_device *pdev)
platform_device_unregister(omap->dwc3); platform_device_unregister(omap->dwc3);
dwc3_put_device_id(omap->dwc3->id); dwc3_put_device_id(omap->dwc3->id);
free_irq(omap->irq, omap);
iounmap(omap->base);
kfree(omap->context);
kfree(omap);
return 0; return 0;
} }
......
...@@ -61,19 +61,20 @@ static int __devinit dwc3_pci_probe(struct pci_dev *pci, ...@@ -61,19 +61,20 @@ static int __devinit dwc3_pci_probe(struct pci_dev *pci,
struct dwc3_pci *glue; struct dwc3_pci *glue;
int ret = -ENOMEM; int ret = -ENOMEM;
int devid; int devid;
struct device *dev = &pci->dev;
glue = kzalloc(sizeof(*glue), GFP_KERNEL); glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL);
if (!glue) { if (!glue) {
dev_err(&pci->dev, "not enough memory\n"); dev_err(dev, "not enough memory\n");
goto err0; return -ENOMEM;
} }
glue->dev = &pci->dev; glue->dev = dev;
ret = pci_enable_device(pci); ret = pci_enable_device(pci);
if (ret) { if (ret) {
dev_err(&pci->dev, "failed to enable pci device\n"); dev_err(dev, "failed to enable pci device\n");
goto err1; return -ENODEV;
} }
pci_set_power_state(pci, PCI_D0); pci_set_power_state(pci, PCI_D0);
...@@ -81,12 +82,12 @@ static int __devinit dwc3_pci_probe(struct pci_dev *pci, ...@@ -81,12 +82,12 @@ static int __devinit dwc3_pci_probe(struct pci_dev *pci,
devid = dwc3_get_device_id(); devid = dwc3_get_device_id();
if (devid < 0) if (devid < 0)
goto err2; goto err1;
dwc3 = platform_device_alloc("dwc3", devid); dwc3 = platform_device_alloc("dwc3", devid);
if (!dwc3) { if (!dwc3) {
dev_err(&pci->dev, "couldn't allocate dwc3 device\n"); dev_err(dev, "couldn't allocate dwc3 device\n");
goto err3; goto err1;
} }
memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
...@@ -102,41 +103,37 @@ static int __devinit dwc3_pci_probe(struct pci_dev *pci, ...@@ -102,41 +103,37 @@ static int __devinit dwc3_pci_probe(struct pci_dev *pci,
ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res)); ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res));
if (ret) { if (ret) {
dev_err(&pci->dev, "couldn't add resources to dwc3 device\n"); dev_err(dev, "couldn't add resources to dwc3 device\n");
goto err4; goto err2;
} }
pci_set_drvdata(pci, glue); pci_set_drvdata(pci, glue);
dma_set_coherent_mask(&dwc3->dev, pci->dev.coherent_dma_mask); dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask);
dwc3->dev.dma_mask = pci->dev.dma_mask; dwc3->dev.dma_mask = dev->dma_mask;
dwc3->dev.dma_parms = pci->dev.dma_parms; dwc3->dev.dma_parms = dev->dma_parms;
dwc3->dev.parent = &pci->dev; dwc3->dev.parent = dev;
glue->dwc3 = dwc3; glue->dwc3 = dwc3;
ret = platform_device_add(dwc3); ret = platform_device_add(dwc3);
if (ret) { if (ret) {
dev_err(&pci->dev, "failed to register dwc3 device\n"); dev_err(dev, "failed to register dwc3 device\n");
goto err4; goto err3;
} }
return 0; return 0;
err4: err3:
pci_set_drvdata(pci, NULL); pci_set_drvdata(pci, NULL);
platform_device_put(dwc3); platform_device_put(dwc3);
err3:
dwc3_put_device_id(devid);
err2: err2:
pci_disable_device(pci); dwc3_put_device_id(devid);
err1: err1:
kfree(glue); pci_disable_device(pci);
err0:
return ret; return ret;
} }
...@@ -148,7 +145,6 @@ static void __devexit dwc3_pci_remove(struct pci_dev *pci) ...@@ -148,7 +145,6 @@ static void __devexit dwc3_pci_remove(struct pci_dev *pci)
platform_device_unregister(glue->dwc3); platform_device_unregister(glue->dwc3);
pci_set_drvdata(pci, NULL); pci_set_drvdata(pci, NULL);
pci_disable_device(pci); pci_disable_device(pci);
kfree(glue);
} }
static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = { static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册