Commit 933e4af4 authored by Fabio Estevam's avatar Fabio Estevam Committed by Marc Kleine-Budde

can: flexcan: Use devm_ioremap_resource()

Using devm_ioremap_resource() can make the code simpler and smaller.

Also, place alloc_candev() after of_match_device() to make error handling
easier.
Signed-off-by: default avatarFabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 46b3a421
...@@ -1001,7 +1001,6 @@ static int flexcan_probe(struct platform_device *pdev) ...@@ -1001,7 +1001,6 @@ static int flexcan_probe(struct platform_device *pdev)
struct resource *mem; struct resource *mem;
struct clk *clk_ipg = NULL, *clk_per = NULL; struct clk *clk_ipg = NULL, *clk_per = NULL;
void __iomem *base; void __iomem *base;
resource_size_t mem_size;
int err, irq; int err, irq;
u32 clock_freq = 0; u32 clock_freq = 0;
...@@ -1013,43 +1012,25 @@ static int flexcan_probe(struct platform_device *pdev) ...@@ -1013,43 +1012,25 @@ static int flexcan_probe(struct platform_device *pdev)
clk_ipg = devm_clk_get(&pdev->dev, "ipg"); clk_ipg = devm_clk_get(&pdev->dev, "ipg");
if (IS_ERR(clk_ipg)) { if (IS_ERR(clk_ipg)) {
dev_err(&pdev->dev, "no ipg clock defined\n"); dev_err(&pdev->dev, "no ipg clock defined\n");
err = PTR_ERR(clk_ipg); return PTR_ERR(clk_ipg);
goto failed_clock;
} }
clock_freq = clk_get_rate(clk_ipg); clock_freq = clk_get_rate(clk_ipg);
clk_per = devm_clk_get(&pdev->dev, "per"); clk_per = devm_clk_get(&pdev->dev, "per");
if (IS_ERR(clk_per)) { if (IS_ERR(clk_per)) {
dev_err(&pdev->dev, "no per clock defined\n"); dev_err(&pdev->dev, "no per clock defined\n");
err = PTR_ERR(clk_per); return PTR_ERR(clk_per);
goto failed_clock;
} }
} }
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 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)
err = -ENODEV; return -ENODEV;
goto failed_get;
}
mem_size = resource_size(mem);
if (!request_mem_region(mem->start, mem_size, pdev->name)) {
err = -EBUSY;
goto failed_get;
}
base = ioremap(mem->start, mem_size); base = devm_ioremap_resource(&pdev->dev, mem);
if (!base) { if (IS_ERR(base))
err = -ENOMEM; return PTR_ERR(base);
goto failed_map;
}
dev = alloc_candev(sizeof(struct flexcan_priv), 1);
if (!dev) {
err = -ENOMEM;
goto failed_alloc;
}
of_id = of_match_device(flexcan_of_match, &pdev->dev); of_id = of_match_device(flexcan_of_match, &pdev->dev);
if (of_id) { if (of_id) {
...@@ -1058,10 +1039,13 @@ static int flexcan_probe(struct platform_device *pdev) ...@@ -1058,10 +1039,13 @@ static int flexcan_probe(struct platform_device *pdev)
devtype_data = (struct flexcan_devtype_data *) devtype_data = (struct flexcan_devtype_data *)
pdev->id_entry->driver_data; pdev->id_entry->driver_data;
} else { } else {
err = -ENODEV; return -ENODEV;
goto failed_devtype;
} }
dev = alloc_candev(sizeof(struct flexcan_priv), 1);
if (!dev)
return -ENOMEM;
dev->netdev_ops = &flexcan_netdev_ops; dev->netdev_ops = &flexcan_netdev_ops;
dev->irq = irq; dev->irq = irq;
dev->flags |= IFF_ECHO; dev->flags |= IFF_ECHO;
...@@ -1104,28 +1088,15 @@ static int flexcan_probe(struct platform_device *pdev) ...@@ -1104,28 +1088,15 @@ static int flexcan_probe(struct platform_device *pdev)
return 0; return 0;
failed_register: failed_register:
failed_devtype:
free_candev(dev); free_candev(dev);
failed_alloc:
iounmap(base);
failed_map:
release_mem_region(mem->start, mem_size);
failed_get:
failed_clock:
return err; return err;
} }
static int flexcan_remove(struct platform_device *pdev) static int flexcan_remove(struct platform_device *pdev)
{ {
struct net_device *dev = platform_get_drvdata(pdev); struct net_device *dev = platform_get_drvdata(pdev);
struct flexcan_priv *priv = netdev_priv(dev);
struct resource *mem;
unregister_flexcandev(dev); unregister_flexcandev(dev);
iounmap(priv->base);
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(mem->start, resource_size(mem));
free_candev(dev); free_candev(dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment