Commit e8009ca0 authored by Jingoo Han's avatar Jingoo Han Committed by Brian Norris

mtd: nuc900_nand: Use devm_*() functions

Use devm_*() functions to make cleanup paths simpler.
Signed-off-by: default avatarJingoo Han <jg1.han@samsung.com>
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
parent 133432a7
...@@ -241,12 +241,10 @@ static int nuc900_nand_probe(struct platform_device *pdev) ...@@ -241,12 +241,10 @@ static int nuc900_nand_probe(struct platform_device *pdev)
{ {
struct nuc900_nand *nuc900_nand; struct nuc900_nand *nuc900_nand;
struct nand_chip *chip; struct nand_chip *chip;
int retval;
struct resource *res; struct resource *res;
retval = 0; nuc900_nand = devm_kzalloc(&pdev->dev, sizeof(struct nuc900_nand),
GFP_KERNEL);
nuc900_nand = kzalloc(sizeof(struct nuc900_nand), GFP_KERNEL);
if (!nuc900_nand) if (!nuc900_nand)
return -ENOMEM; return -ENOMEM;
chip = &(nuc900_nand->chip); chip = &(nuc900_nand->chip);
...@@ -255,11 +253,9 @@ static int nuc900_nand_probe(struct platform_device *pdev) ...@@ -255,11 +253,9 @@ static int nuc900_nand_probe(struct platform_device *pdev)
nuc900_nand->mtd.owner = THIS_MODULE; nuc900_nand->mtd.owner = THIS_MODULE;
spin_lock_init(&nuc900_nand->lock); spin_lock_init(&nuc900_nand->lock);
nuc900_nand->clk = clk_get(&pdev->dev, NULL); nuc900_nand->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(nuc900_nand->clk)) { if (IS_ERR(nuc900_nand->clk))
retval = -ENOENT; return -ENOENT;
goto fail1;
}
clk_enable(nuc900_nand->clk); clk_enable(nuc900_nand->clk);
chip->cmdfunc = nuc900_nand_command_lp; chip->cmdfunc = nuc900_nand_command_lp;
...@@ -272,57 +268,32 @@ static int nuc900_nand_probe(struct platform_device *pdev) ...@@ -272,57 +268,32 @@ static int nuc900_nand_probe(struct platform_device *pdev)
chip->ecc.mode = NAND_ECC_SOFT; chip->ecc.mode = NAND_ECC_SOFT;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) { if (!res)
retval = -ENXIO; return -ENXIO;
goto fail1;
}
if (!request_mem_region(res->start, resource_size(res), pdev->name)) { nuc900_nand->reg = devm_ioremap_resource(&pdev->dev, res);
retval = -EBUSY; if (IS_ERR(nuc900_nand->reg))
goto fail1; return PTR_ERR(nuc900_nand->reg);
}
nuc900_nand->reg = ioremap(res->start, resource_size(res));
if (!nuc900_nand->reg) {
retval = -ENOMEM;
goto fail2;
}
nuc900_nand_enable(nuc900_nand); nuc900_nand_enable(nuc900_nand);
if (nand_scan(&(nuc900_nand->mtd), 1)) { if (nand_scan(&(nuc900_nand->mtd), 1))
retval = -ENXIO; return -ENXIO;
goto fail3;
}
mtd_device_register(&(nuc900_nand->mtd), partitions, mtd_device_register(&(nuc900_nand->mtd), partitions,
ARRAY_SIZE(partitions)); ARRAY_SIZE(partitions));
platform_set_drvdata(pdev, nuc900_nand); platform_set_drvdata(pdev, nuc900_nand);
return retval; return 0;
fail3: iounmap(nuc900_nand->reg);
fail2: release_mem_region(res->start, resource_size(res));
fail1: kfree(nuc900_nand);
return retval;
} }
static int nuc900_nand_remove(struct platform_device *pdev) static int nuc900_nand_remove(struct platform_device *pdev)
{ {
struct nuc900_nand *nuc900_nand = platform_get_drvdata(pdev); struct nuc900_nand *nuc900_nand = platform_get_drvdata(pdev);
struct resource *res;
nand_release(&nuc900_nand->mtd); nand_release(&nuc900_nand->mtd);
iounmap(nuc900_nand->reg);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(res->start, resource_size(res));
clk_disable(nuc900_nand->clk); clk_disable(nuc900_nand->clk);
clk_put(nuc900_nand->clk);
kfree(nuc900_nand);
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