mtd: plat_nand: Use devm_*() functions

Use devm_*() functions to make cleanup paths simpler.

Signed-off-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
This commit is contained in:
Jingoo Han 2014-01-03 11:16:28 +09:00 committed by Brian Norris
parent ed0b272ed2
commit ffdac7cd31
1 changed files with 6 additions and 25 deletions

View File

@ -9,6 +9,7 @@
* *
*/ */
#include <linux/err.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
@ -52,25 +53,16 @@ static int plat_nand_probe(struct platform_device *pdev)
return -ENXIO; return -ENXIO;
/* Allocate memory for the device structure (and zero it) */ /* Allocate memory for the device structure (and zero it) */
data = kzalloc(sizeof(struct plat_nand_data), GFP_KERNEL); data = devm_kzalloc(&pdev->dev, sizeof(struct plat_nand_data),
GFP_KERNEL);
if (!data) { if (!data) {
dev_err(&pdev->dev, "failed to allocate device structure.\n"); dev_err(&pdev->dev, "failed to allocate device structure.\n");
return -ENOMEM; return -ENOMEM;
} }
if (!request_mem_region(res->start, resource_size(res), data->io_base = devm_ioremap_resource(&pdev->dev, res);
dev_name(&pdev->dev))) { if (IS_ERR(data->io_base))
dev_err(&pdev->dev, "request_mem_region failed\n"); return PTR_ERR(data->io_base);
err = -EBUSY;
goto out_free;
}
data->io_base = ioremap(res->start, resource_size(res));
if (data->io_base == NULL) {
dev_err(&pdev->dev, "ioremap failed\n");
err = -EIO;
goto out_release_io;
}
data->chip.priv = &data; data->chip.priv = &data;
data->mtd.priv = &data->chip; data->mtd.priv = &data->chip;
@ -122,11 +114,6 @@ static int plat_nand_probe(struct platform_device *pdev)
out: out:
if (pdata->ctrl.remove) if (pdata->ctrl.remove)
pdata->ctrl.remove(pdev); pdata->ctrl.remove(pdev);
iounmap(data->io_base);
out_release_io:
release_mem_region(res->start, resource_size(res));
out_free:
kfree(data);
return err; return err;
} }
@ -137,16 +124,10 @@ static int plat_nand_remove(struct platform_device *pdev)
{ {
struct plat_nand_data *data = platform_get_drvdata(pdev); struct plat_nand_data *data = platform_get_drvdata(pdev);
struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev); struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev);
struct resource *res;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
nand_release(&data->mtd); nand_release(&data->mtd);
if (pdata->ctrl.remove) if (pdata->ctrl.remove)
pdata->ctrl.remove(pdev); pdata->ctrl.remove(pdev);
iounmap(data->io_base);
release_mem_region(res->start, resource_size(res));
kfree(data);
return 0; return 0;
} }