提交 c6bf7e5f 编写于 作者: L Lad, Prabhakar 提交者: Marc Kleine-Budde

can: c_can: convert to use devm * api

This patch uses devm_* APIs as they are device managed and make code simpler.
Signed-off-by: NLad, Prabhakar <prabhakar.csengg@gmail.com>
Signed-off-by: NMarc Kleine-Budde <mkl@pengutronix.de>
上级 0854a7f1
...@@ -208,40 +208,31 @@ static int c_can_plat_probe(struct platform_device *pdev) ...@@ -208,40 +208,31 @@ static int c_can_plat_probe(struct platform_device *pdev)
} }
/* get the appropriate clk */ /* get the appropriate clk */
clk = clk_get(&pdev->dev, NULL); clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(clk)) { if (IS_ERR(clk)) {
dev_err(&pdev->dev, "no clock defined\n"); ret = PTR_ERR(clk);
ret = -ENODEV;
goto exit; goto exit;
} }
/* get the platform data */ /* get the platform data */
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (!mem || irq <= 0) { if (irq <= 0) {
ret = -ENODEV; ret = -ENODEV;
goto exit_free_clk; goto exit;
}
if (!request_mem_region(mem->start, resource_size(mem),
KBUILD_MODNAME)) {
dev_err(&pdev->dev, "resource unavailable\n");
ret = -ENODEV;
goto exit_free_clk;
} }
addr = ioremap(mem->start, resource_size(mem)); mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!addr) { addr = devm_ioremap_resource(&pdev->dev, mem);
dev_err(&pdev->dev, "failed to map can port\n"); if (IS_ERR(addr)) {
ret = -ENOMEM; ret = PTR_ERR(addr);
goto exit_release_mem; goto exit;
} }
/* allocate the c_can device */ /* allocate the c_can device */
dev = alloc_c_can_dev(); dev = alloc_c_can_dev();
if (!dev) { if (!dev) {
ret = -ENOMEM; ret = -ENOMEM;
goto exit_iounmap; goto exit;
} }
priv = netdev_priv(dev); priv = netdev_priv(dev);
...@@ -321,12 +312,6 @@ static int c_can_plat_probe(struct platform_device *pdev) ...@@ -321,12 +312,6 @@ static int c_can_plat_probe(struct platform_device *pdev)
exit_free_device: exit_free_device:
free_c_can_dev(dev); free_c_can_dev(dev);
exit_iounmap:
iounmap(addr);
exit_release_mem:
release_mem_region(mem->start, resource_size(mem));
exit_free_clk:
clk_put(clk);
exit: exit:
dev_err(&pdev->dev, "probe failed\n"); dev_err(&pdev->dev, "probe failed\n");
...@@ -336,18 +321,10 @@ static int c_can_plat_probe(struct platform_device *pdev) ...@@ -336,18 +321,10 @@ static int c_can_plat_probe(struct platform_device *pdev)
static int c_can_plat_remove(struct platform_device *pdev) static int c_can_plat_remove(struct platform_device *pdev)
{ {
struct net_device *dev = platform_get_drvdata(pdev); struct net_device *dev = platform_get_drvdata(pdev);
struct c_can_priv *priv = netdev_priv(dev);
struct resource *mem;
unregister_c_can_dev(dev); unregister_c_can_dev(dev);
free_c_can_dev(dev); free_c_can_dev(dev);
iounmap(priv->base);
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(mem->start, resource_size(mem));
clk_put(priv->priv);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册