提交 98515e59 编写于 作者: V Viresh Kumar 提交者: Greg Kroah-Hartman

usb: spear-ehci/ohci: Use devm_*() routines

This patch frees SPEAr ehci/ohci drivers from tension of freeing resources :)
devm_* derivatives of multiple routines are used while allocating resources,
which would be freed automatically by kernel.
Signed-off-by: NViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 d8fd7d5a
...@@ -116,7 +116,7 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev) ...@@ -116,7 +116,7 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) { if (irq < 0) {
retval = irq; retval = irq;
goto fail_irq_get; goto fail;
} }
/* /*
...@@ -127,38 +127,38 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev) ...@@ -127,38 +127,38 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
if (!pdev->dev.dma_mask) if (!pdev->dev.dma_mask)
pdev->dev.dma_mask = &spear_ehci_dma_mask; pdev->dev.dma_mask = &spear_ehci_dma_mask;
usbh_clk = clk_get(&pdev->dev, NULL); usbh_clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(usbh_clk)) { if (IS_ERR(usbh_clk)) {
dev_err(&pdev->dev, "Error getting interface clock\n"); dev_err(&pdev->dev, "Error getting interface clock\n");
retval = PTR_ERR(usbh_clk); retval = PTR_ERR(usbh_clk);
goto fail_get_usbh_clk; goto fail;
} }
hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
if (!hcd) { if (!hcd) {
retval = -ENOMEM; retval = -ENOMEM;
goto fail_create_hcd; goto fail;
} }
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) { if (!res) {
retval = -ENODEV; retval = -ENODEV;
goto fail_request_resource; goto err_put_hcd;
} }
hcd->rsrc_start = res->start; hcd->rsrc_start = res->start;
hcd->rsrc_len = resource_size(res); hcd->rsrc_len = resource_size(res);
if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, if (!devm_request_mem_region(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len,
driver->description)) { driver->description)) {
retval = -EBUSY; retval = -EBUSY;
goto fail_request_resource; goto err_put_hcd;
} }
hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
if (hcd->regs == NULL) { if (hcd->regs == NULL) {
dev_dbg(&pdev->dev, "error mapping memory\n"); dev_dbg(&pdev->dev, "error mapping memory\n");
retval = -ENOMEM; retval = -ENOMEM;
goto fail_ioremap; goto err_put_hcd;
} }
ehci = (struct spear_ehci *)hcd_to_ehci(hcd); ehci = (struct spear_ehci *)hcd_to_ehci(hcd);
...@@ -167,21 +167,15 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev) ...@@ -167,21 +167,15 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
spear_start_ehci(ehci); spear_start_ehci(ehci);
retval = usb_add_hcd(hcd, irq, IRQF_SHARED); retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
if (retval) if (retval)
goto fail_add_hcd; goto err_stop_ehci;
return retval; return retval;
fail_add_hcd: err_stop_ehci:
spear_stop_ehci(ehci); spear_stop_ehci(ehci);
iounmap(hcd->regs); err_put_hcd:
fail_ioremap:
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
fail_request_resource:
usb_put_hcd(hcd); usb_put_hcd(hcd);
fail_create_hcd: fail:
clk_put(usbh_clk);
fail_get_usbh_clk:
fail_irq_get:
dev_err(&pdev->dev, "init fail, %d\n", retval); dev_err(&pdev->dev, "init fail, %d\n", retval);
return retval ; return retval ;
...@@ -200,13 +194,8 @@ static int spear_ehci_hcd_drv_remove(struct platform_device *pdev) ...@@ -200,13 +194,8 @@ static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
if (ehci_p->clk) if (ehci_p->clk)
spear_stop_ehci(ehci_p); spear_stop_ehci(ehci_p);
iounmap(hcd->regs);
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
usb_put_hcd(hcd); usb_put_hcd(hcd);
if (ehci_p->clk)
clk_put(ehci_p->clk);
return 0; return 0;
} }
......
...@@ -105,7 +105,7 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) ...@@ -105,7 +105,7 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) { if (irq < 0) {
retval = irq; retval = irq;
goto fail_irq_get; goto fail;
} }
/* /*
...@@ -116,38 +116,39 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) ...@@ -116,38 +116,39 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
if (!pdev->dev.dma_mask) if (!pdev->dev.dma_mask)
pdev->dev.dma_mask = &spear_ohci_dma_mask; pdev->dev.dma_mask = &spear_ohci_dma_mask;
usbh_clk = clk_get(&pdev->dev, NULL); usbh_clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(usbh_clk)) { if (IS_ERR(usbh_clk)) {
dev_err(&pdev->dev, "Error getting interface clock\n"); dev_err(&pdev->dev, "Error getting interface clock\n");
retval = PTR_ERR(usbh_clk); retval = PTR_ERR(usbh_clk);
goto fail_get_usbh_clk; goto fail;
} }
hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
if (!hcd) { if (!hcd) {
retval = -ENOMEM; retval = -ENOMEM;
goto fail_create_hcd; goto fail;
} }
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) { if (!res) {
retval = -ENODEV; retval = -ENODEV;
goto fail_request_resource; goto err_put_hcd;
} }
hcd->rsrc_start = pdev->resource[0].start; hcd->rsrc_start = pdev->resource[0].start;
hcd->rsrc_len = resource_size(res); hcd->rsrc_len = resource_size(res);
if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { if (!devm_request_mem_region(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len,
hcd_name)) {
dev_dbg(&pdev->dev, "request_mem_region failed\n"); dev_dbg(&pdev->dev, "request_mem_region failed\n");
retval = -EBUSY; retval = -EBUSY;
goto fail_request_resource; goto err_put_hcd;
} }
hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
if (!hcd->regs) { if (!hcd->regs) {
dev_dbg(&pdev->dev, "ioremap failed\n"); dev_dbg(&pdev->dev, "ioremap failed\n");
retval = -ENOMEM; retval = -ENOMEM;
goto fail_ioremap; goto err_put_hcd;
} }
ohci_p = (struct spear_ohci *)hcd_to_ohci(hcd); ohci_p = (struct spear_ohci *)hcd_to_ohci(hcd);
...@@ -160,15 +161,9 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) ...@@ -160,15 +161,9 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
return retval; return retval;
spear_stop_ohci(ohci_p); spear_stop_ohci(ohci_p);
iounmap(hcd->regs); err_put_hcd:
fail_ioremap:
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
fail_request_resource:
usb_put_hcd(hcd); usb_put_hcd(hcd);
fail_create_hcd: fail:
clk_put(usbh_clk);
fail_get_usbh_clk:
fail_irq_get:
dev_err(&pdev->dev, "init fail, %d\n", retval); dev_err(&pdev->dev, "init fail, %d\n", retval);
return retval; return retval;
...@@ -183,12 +178,8 @@ static int spear_ohci_hcd_drv_remove(struct platform_device *pdev) ...@@ -183,12 +178,8 @@ static int spear_ohci_hcd_drv_remove(struct platform_device *pdev)
if (ohci_p->clk) if (ohci_p->clk)
spear_stop_ohci(ohci_p); spear_stop_ohci(ohci_p);
iounmap(hcd->regs);
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
usb_put_hcd(hcd); usb_put_hcd(hcd);
if (ohci_p->clk)
clk_put(ohci_p->clk);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册