mtd: s3c2410: Use devm_* functions
devm_* functions are device managed functions and make cleanup code simpler and smaller. devm_kzalloc, devm_clk_get and devm_request_and_ioremap functions are used. Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
This commit is contained in:
parent
c83d29f008
commit
6f32a3e285
@ -97,9 +97,8 @@ enum s3c_nand_clk_state {
|
|||||||
* @mtds: An array of MTD instances on this controoler.
|
* @mtds: An array of MTD instances on this controoler.
|
||||||
* @platform: The platform data for this board.
|
* @platform: The platform data for this board.
|
||||||
* @device: The platform device we bound to.
|
* @device: The platform device we bound to.
|
||||||
* @area: The IO area resource that came from request_mem_region().
|
|
||||||
* @clk: The clock resource for this controller.
|
* @clk: The clock resource for this controller.
|
||||||
* @regs: The area mapped for the hardware registers described by @area.
|
* @regs: The area mapped for the hardware registers.
|
||||||
* @sel_reg: Pointer to the register controlling the NAND selection.
|
* @sel_reg: Pointer to the register controlling the NAND selection.
|
||||||
* @sel_bit: The bit in @sel_reg to select the NAND chip.
|
* @sel_bit: The bit in @sel_reg to select the NAND chip.
|
||||||
* @mtd_count: The number of MTDs created from this controller.
|
* @mtd_count: The number of MTDs created from this controller.
|
||||||
@ -116,7 +115,6 @@ struct s3c2410_nand_info {
|
|||||||
|
|
||||||
/* device info */
|
/* device info */
|
||||||
struct device *device;
|
struct device *device;
|
||||||
struct resource *area;
|
|
||||||
struct clk *clk;
|
struct clk *clk;
|
||||||
void __iomem *regs;
|
void __iomem *regs;
|
||||||
void __iomem *sel_reg;
|
void __iomem *sel_reg;
|
||||||
@ -716,29 +714,12 @@ static int s3c24xx_nand_remove(struct platform_device *pdev)
|
|||||||
pr_debug("releasing mtd %d (%p)\n", mtdno, ptr);
|
pr_debug("releasing mtd %d (%p)\n", mtdno, ptr);
|
||||||
nand_release(&ptr->mtd);
|
nand_release(&ptr->mtd);
|
||||||
}
|
}
|
||||||
|
|
||||||
kfree(info->mtds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free the common resources */
|
/* free the common resources */
|
||||||
|
|
||||||
if (!IS_ERR(info->clk)) {
|
if (!IS_ERR(info->clk))
|
||||||
s3c2410_nand_clk_set_state(info, CLOCK_DISABLE);
|
s3c2410_nand_clk_set_state(info, CLOCK_DISABLE);
|
||||||
clk_put(info->clk);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (info->regs != NULL) {
|
|
||||||
iounmap(info->regs);
|
|
||||||
info->regs = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (info->area != NULL) {
|
|
||||||
release_resource(info->area);
|
|
||||||
kfree(info->area);
|
|
||||||
info->area = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
kfree(info);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -933,7 +914,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
pr_debug("s3c2410_nand_probe(%p)\n", pdev);
|
pr_debug("s3c2410_nand_probe(%p)\n", pdev);
|
||||||
|
|
||||||
info = kzalloc(sizeof(*info), GFP_KERNEL);
|
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
|
||||||
if (info == NULL) {
|
if (info == NULL) {
|
||||||
dev_err(&pdev->dev, "no memory for flash info\n");
|
dev_err(&pdev->dev, "no memory for flash info\n");
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
@ -947,7 +928,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
/* get the clock source and enable it */
|
/* get the clock source and enable it */
|
||||||
|
|
||||||
info->clk = clk_get(&pdev->dev, "nand");
|
info->clk = devm_clk_get(&pdev->dev, "nand");
|
||||||
if (IS_ERR(info->clk)) {
|
if (IS_ERR(info->clk)) {
|
||||||
dev_err(&pdev->dev, "failed to get clock\n");
|
dev_err(&pdev->dev, "failed to get clock\n");
|
||||||
err = -ENOENT;
|
err = -ENOENT;
|
||||||
@ -959,22 +940,14 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)
|
|||||||
/* allocate and map the resource */
|
/* allocate and map the resource */
|
||||||
|
|
||||||
/* currently we assume we have the one resource */
|
/* currently we assume we have the one resource */
|
||||||
res = pdev->resource;
|
res = pdev->resource;
|
||||||
size = resource_size(res);
|
size = resource_size(res);
|
||||||
|
|
||||||
info->area = request_mem_region(res->start, size, pdev->name);
|
info->device = &pdev->dev;
|
||||||
|
info->platform = plat;
|
||||||
if (info->area == NULL) {
|
info->cpu_type = cpu_type;
|
||||||
dev_err(&pdev->dev, "cannot reserve register region\n");
|
|
||||||
err = -ENOENT;
|
|
||||||
goto exit_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
info->device = &pdev->dev;
|
|
||||||
info->platform = plat;
|
|
||||||
info->regs = ioremap(res->start, size);
|
|
||||||
info->cpu_type = cpu_type;
|
|
||||||
|
|
||||||
|
info->regs = devm_request_and_ioremap(&pdev->dev, res);
|
||||||
if (info->regs == NULL) {
|
if (info->regs == NULL) {
|
||||||
dev_err(&pdev->dev, "cannot reserve register region\n");
|
dev_err(&pdev->dev, "cannot reserve register region\n");
|
||||||
err = -EIO;
|
err = -EIO;
|
||||||
@ -997,7 +970,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)
|
|||||||
/* allocate our information */
|
/* allocate our information */
|
||||||
|
|
||||||
size = nr_sets * sizeof(*info->mtds);
|
size = nr_sets * sizeof(*info->mtds);
|
||||||
info->mtds = kzalloc(size, GFP_KERNEL);
|
info->mtds = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
|
||||||
if (info->mtds == NULL) {
|
if (info->mtds == NULL) {
|
||||||
dev_err(&pdev->dev, "failed to allocate mtd storage\n");
|
dev_err(&pdev->dev, "failed to allocate mtd storage\n");
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
|
Loading…
Reference in New Issue
Block a user