Commit e1ed147f authored by Julia Lawall's avatar Julia Lawall Committed by David Woodhouse

mtd: spear_smi: use devm_ functions consistently

Use devm_kzalloc for all calls to kzalloc and not just the first.  Use devm
functions for other allocations as well.

Move the call to platform_get_resource(pdev, IORESOURCE_MEM, 0) closer to
where its result is passed to devm_request_and_ioremap to make the lack of
need for a NULL test more evident.

The semantic match that finds the inconsistency is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
@@

*devm_kzalloc(...)
...
*kzalloc(...)
// </smpl>
Signed-off-by: default avatarJulia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: default avatarArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent 99f2b107
...@@ -827,7 +827,7 @@ static int spear_smi_setup_banks(struct platform_device *pdev, ...@@ -827,7 +827,7 @@ static int spear_smi_setup_banks(struct platform_device *pdev,
if (!flash_info) if (!flash_info)
return -ENODEV; return -ENODEV;
flash = kzalloc(sizeof(*flash), GFP_ATOMIC); flash = devm_kzalloc(&pdev->dev, sizeof(*flash), GFP_ATOMIC);
if (!flash) if (!flash)
return -ENOMEM; return -ENOMEM;
flash->bank = bank; flash->bank = bank;
...@@ -838,15 +838,13 @@ static int spear_smi_setup_banks(struct platform_device *pdev, ...@@ -838,15 +838,13 @@ static int spear_smi_setup_banks(struct platform_device *pdev,
flash_index = spear_smi_probe_flash(dev, bank); flash_index = spear_smi_probe_flash(dev, bank);
if (flash_index < 0) { if (flash_index < 0) {
dev_info(&dev->pdev->dev, "smi-nor%d not found\n", bank); dev_info(&dev->pdev->dev, "smi-nor%d not found\n", bank);
ret = flash_index; return flash_index;
goto err_probe;
} }
/* map the memory for nor flash chip */ /* map the memory for nor flash chip */
flash->base_addr = ioremap(flash_info->mem_base, flash_info->size); flash->base_addr = devm_ioremap(&pdev->dev, flash_info->mem_base,
if (!flash->base_addr) { flash_info->size);
ret = -EIO; if (!flash->base_addr)
goto err_probe; return -EIO;
}
dev->flash[bank] = flash; dev->flash[bank] = flash;
flash->mtd.priv = dev; flash->mtd.priv = dev;
...@@ -888,17 +886,10 @@ static int spear_smi_setup_banks(struct platform_device *pdev, ...@@ -888,17 +886,10 @@ static int spear_smi_setup_banks(struct platform_device *pdev,
count); count);
if (ret) { if (ret) {
dev_err(&dev->pdev->dev, "Err MTD partition=%d\n", ret); dev_err(&dev->pdev->dev, "Err MTD partition=%d\n", ret);
goto err_map; return ret;
} }
return 0; return 0;
err_map:
iounmap(flash->base_addr);
err_probe:
kfree(flash);
return ret;
} }
/** /**
...@@ -942,13 +933,6 @@ static int __devinit spear_smi_probe(struct platform_device *pdev) ...@@ -942,13 +933,6 @@ static int __devinit spear_smi_probe(struct platform_device *pdev)
} }
} }
smi_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!smi_base) {
ret = -ENODEV;
dev_err(&pdev->dev, "invalid smi base address\n");
goto err;
}
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) { if (irq < 0) {
ret = -ENODEV; ret = -ENODEV;
...@@ -956,26 +940,20 @@ static int __devinit spear_smi_probe(struct platform_device *pdev) ...@@ -956,26 +940,20 @@ static int __devinit spear_smi_probe(struct platform_device *pdev)
goto err; goto err;
} }
dev = kzalloc(sizeof(*dev), GFP_ATOMIC); dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_ATOMIC);
if (!dev) { if (!dev) {
ret = -ENOMEM; ret = -ENOMEM;
dev_err(&pdev->dev, "mem alloc fail\n"); dev_err(&pdev->dev, "mem alloc fail\n");
goto err; goto err;
} }
smi_base = request_mem_region(smi_base->start, resource_size(smi_base), smi_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
pdev->name);
if (!smi_base) {
ret = -EBUSY;
dev_err(&pdev->dev, "request mem region fail\n");
goto err_mem;
}
dev->io_base = ioremap(smi_base->start, resource_size(smi_base)); dev->io_base = devm_request_and_ioremap(&pdev->dev, smi_base);
if (!dev->io_base) { if (!dev->io_base) {
ret = -EIO; ret = -EIO;
dev_err(&pdev->dev, "ioremap fail\n"); dev_err(&pdev->dev, "devm_request_and_ioremap fail\n");
goto err_ioremap; goto err;
} }
dev->pdev = pdev; dev->pdev = pdev;
...@@ -991,17 +969,18 @@ static int __devinit spear_smi_probe(struct platform_device *pdev) ...@@ -991,17 +969,18 @@ static int __devinit spear_smi_probe(struct platform_device *pdev)
dev->num_flashes = MAX_NUM_FLASH_CHIP; dev->num_flashes = MAX_NUM_FLASH_CHIP;
} }
dev->clk = clk_get(&pdev->dev, NULL); dev->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(dev->clk)) { if (IS_ERR(dev->clk)) {
ret = PTR_ERR(dev->clk); ret = PTR_ERR(dev->clk);
goto err_clk; goto err;
} }
ret = clk_prepare_enable(dev->clk); ret = clk_prepare_enable(dev->clk);
if (ret) if (ret)
goto err_clk_prepare_enable; goto err;
ret = request_irq(irq, spear_smi_int_handler, 0, pdev->name, dev); ret = devm_request_irq(&pdev->dev, irq, spear_smi_int_handler, 0,
pdev->name, dev);
if (ret) { if (ret) {
dev_err(&dev->pdev->dev, "SMI IRQ allocation failed\n"); dev_err(&dev->pdev->dev, "SMI IRQ allocation failed\n");
goto err_irq; goto err_irq;
...@@ -1024,18 +1003,9 @@ static int __devinit spear_smi_probe(struct platform_device *pdev) ...@@ -1024,18 +1003,9 @@ static int __devinit spear_smi_probe(struct platform_device *pdev)
return 0; return 0;
err_bank_setup: err_bank_setup:
free_irq(irq, dev);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
err_irq: err_irq:
clk_disable_unprepare(dev->clk); clk_disable_unprepare(dev->clk);
err_clk_prepare_enable:
clk_put(dev->clk);
err_clk:
iounmap(dev->io_base);
err_ioremap:
release_mem_region(smi_base->start, resource_size(smi_base));
err_mem:
kfree(dev);
err: err:
return ret; return ret;
} }
...@@ -1049,11 +1019,8 @@ static int __devinit spear_smi_probe(struct platform_device *pdev) ...@@ -1049,11 +1019,8 @@ static int __devinit spear_smi_probe(struct platform_device *pdev)
static int __devexit spear_smi_remove(struct platform_device *pdev) static int __devexit spear_smi_remove(struct platform_device *pdev)
{ {
struct spear_smi *dev; struct spear_smi *dev;
struct spear_smi_plat_data *pdata;
struct spear_snor_flash *flash; struct spear_snor_flash *flash;
struct resource *smi_base; int ret, i;
int ret;
int i, irq;
dev = platform_get_drvdata(pdev); dev = platform_get_drvdata(pdev);
if (!dev) { if (!dev) {
...@@ -1061,8 +1028,6 @@ static int __devexit spear_smi_remove(struct platform_device *pdev) ...@@ -1061,8 +1028,6 @@ static int __devexit spear_smi_remove(struct platform_device *pdev)
return -ENODEV; return -ENODEV;
} }
pdata = dev_get_platdata(&pdev->dev);
/* clean up for all nor flash */ /* clean up for all nor flash */
for (i = 0; i < dev->num_flashes; i++) { for (i = 0; i < dev->num_flashes; i++) {
flash = dev->flash[i]; flash = dev->flash[i];
...@@ -1073,21 +1038,9 @@ static int __devexit spear_smi_remove(struct platform_device *pdev) ...@@ -1073,21 +1038,9 @@ static int __devexit spear_smi_remove(struct platform_device *pdev)
ret = mtd_device_unregister(&flash->mtd); ret = mtd_device_unregister(&flash->mtd);
if (ret) if (ret)
dev_err(&pdev->dev, "error removing mtd\n"); dev_err(&pdev->dev, "error removing mtd\n");
iounmap(flash->base_addr);
kfree(flash);
} }
irq = platform_get_irq(pdev, 0);
free_irq(irq, dev);
clk_disable_unprepare(dev->clk); clk_disable_unprepare(dev->clk);
clk_put(dev->clk);
iounmap(dev->io_base);
kfree(dev);
smi_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(smi_base->start, resource_size(smi_base));
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
return 0; return 0;
......
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