Commit 82b9dbe2 authored by Vipin Kumar's avatar Vipin Kumar Committed by David Woodhouse

mtd: nand/fsmc: Use devm routines

fsmc_nand driver currently uses normal kzalloc, request_mem etc routines. This
patch replaces these routines with devm_kzalloc and devm_request_mem_region etc.
Consequently, the error and driver removal scenarios are curtailed.
Signed-off-by: default avatarVipin Kumar <vipin.kumar@st.com>
Reviewed-by: default avatarViresh Kumar <viresh.kumar@st.com>
Signed-off-by: default avatarArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent e2f6bce8
...@@ -298,11 +298,6 @@ struct fsmc_nand_data { ...@@ -298,11 +298,6 @@ struct fsmc_nand_data {
unsigned int bank; unsigned int bank;
struct clk *clk; struct clk *clk;
struct resource *resregs;
struct resource *rescmd;
struct resource *resaddr;
struct resource *resdata;
struct fsmc_nand_timings *dev_timings; struct fsmc_nand_timings *dev_timings;
void __iomem *data_va; void __iomem *data_va;
...@@ -706,88 +701,81 @@ static int __init fsmc_nand_probe(struct platform_device *pdev) ...@@ -706,88 +701,81 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
} }
/* Allocate memory for the device structure (and zero it) */ /* Allocate memory for the device structure (and zero it) */
host = kzalloc(sizeof(*host), GFP_KERNEL); host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
if (!host) { if (!host) {
dev_err(&pdev->dev, "failed to allocate device structure\n"); dev_err(&pdev->dev, "failed to allocate device structure\n");
return -ENOMEM; return -ENOMEM;
} }
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_data"); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_data");
if (!res) { if (!res)
ret = -EIO; return -EINVAL;
goto err_probe1;
}
host->resdata = request_mem_region(res->start, resource_size(res), if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res),
pdev->name); pdev->name)) {
if (!host->resdata) { dev_err(&pdev->dev, "Failed to get memory data resourse\n");
ret = -EIO; return -ENOENT;
goto err_probe1;
} }
host->data_va = ioremap(res->start, resource_size(res)); host->data_va = devm_ioremap(&pdev->dev, res->start,
resource_size(res));
if (!host->data_va) { if (!host->data_va) {
ret = -EIO; dev_err(&pdev->dev, "data ioremap failed\n");
goto err_probe1; return -ENOMEM;
} }
host->resaddr = request_mem_region(res->start + pdata->ale_off, if (!devm_request_mem_region(&pdev->dev, res->start + pdata->ale_off,
resource_size(res), pdev->name); resource_size(res), pdev->name)) {
if (!host->resaddr) { dev_err(&pdev->dev, "Failed to get memory ale resourse\n");
ret = -EIO; return -ENOENT;
goto err_probe1;
} }
host->addr_va = ioremap(res->start + pdata->ale_off, host->addr_va = devm_ioremap(&pdev->dev, res->start + pdata->ale_off,
resource_size(res)); resource_size(res));
if (!host->addr_va) { if (!host->addr_va) {
ret = -EIO; dev_err(&pdev->dev, "ale ioremap failed\n");
goto err_probe1; return -ENOMEM;
} }
host->rescmd = request_mem_region(res->start + pdata->cle_off, if (!devm_request_mem_region(&pdev->dev, res->start + pdata->cle_off,
resource_size(res), pdev->name); resource_size(res), pdev->name)) {
if (!host->rescmd) { dev_err(&pdev->dev, "Failed to get memory cle resourse\n");
ret = -EIO; return -ENOENT;
goto err_probe1;
} }
host->cmd_va = ioremap(res->start + pdata->cle_off, resource_size(res)); host->cmd_va = devm_ioremap(&pdev->dev, res->start + pdata->cle_off,
resource_size(res));
if (!host->cmd_va) { if (!host->cmd_va) {
ret = -EIO; dev_err(&pdev->dev, "ale ioremap failed\n");
goto err_probe1; return -ENOMEM;
} }
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fsmc_regs"); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fsmc_regs");
if (!res) { if (!res)
ret = -EIO; return -EINVAL;
goto err_probe1;
}
host->resregs = request_mem_region(res->start, resource_size(res), if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res),
pdev->name); pdev->name)) {
if (!host->resregs) { dev_err(&pdev->dev, "Failed to get memory regs resourse\n");
ret = -EIO; return -ENOENT;
goto err_probe1;
} }
host->regs_va = ioremap(res->start, resource_size(res)); host->regs_va = devm_ioremap(&pdev->dev, res->start,
resource_size(res));
if (!host->regs_va) { if (!host->regs_va) {
ret = -EIO; dev_err(&pdev->dev, "regs ioremap failed\n");
goto err_probe1; return -ENOMEM;
} }
host->clk = clk_get(&pdev->dev, NULL); host->clk = clk_get(&pdev->dev, NULL);
if (IS_ERR(host->clk)) { if (IS_ERR(host->clk)) {
dev_err(&pdev->dev, "failed to fetch block clock\n"); dev_err(&pdev->dev, "failed to fetch block clock\n");
ret = PTR_ERR(host->clk); return PTR_ERR(host->clk);
host->clk = NULL;
goto err_probe1;
} }
ret = clk_enable(host->clk); ret = clk_enable(host->clk);
if (ret) if (ret)
goto err_probe1; goto err_clk_enable;
/* /*
* This device ID is actually a common AMBA ID as used on the * This device ID is actually a common AMBA ID as used on the
...@@ -852,7 +840,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev) ...@@ -852,7 +840,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
if (nand_scan_ident(&host->mtd, 1, NULL)) { if (nand_scan_ident(&host->mtd, 1, NULL)) {
ret = -ENXIO; ret = -ENXIO;
dev_err(&pdev->dev, "No NAND Device found!\n"); dev_err(&pdev->dev, "No NAND Device found!\n");
goto err_probe; goto err_scan_ident;
} }
if (AMBA_REV_BITS(host->pid) >= 8) { if (AMBA_REV_BITS(host->pid) >= 8) {
...@@ -927,32 +915,10 @@ static int __init fsmc_nand_probe(struct platform_device *pdev) ...@@ -927,32 +915,10 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
return 0; return 0;
err_probe: err_probe:
err_scan_ident:
clk_disable(host->clk); clk_disable(host->clk);
err_probe1: err_clk_enable:
if (host->clk) clk_put(host->clk);
clk_put(host->clk);
if (host->regs_va)
iounmap(host->regs_va);
if (host->resregs)
release_mem_region(host->resregs->start,
resource_size(host->resregs));
if (host->cmd_va)
iounmap(host->cmd_va);
if (host->rescmd)
release_mem_region(host->rescmd->start,
resource_size(host->rescmd));
if (host->addr_va)
iounmap(host->addr_va);
if (host->resaddr)
release_mem_region(host->resaddr->start,
resource_size(host->resaddr));
if (host->data_va)
iounmap(host->data_va);
if (host->resdata)
release_mem_region(host->resdata->start,
resource_size(host->resdata));
kfree(host);
return ret; return ret;
} }
...@@ -969,22 +935,8 @@ static int fsmc_nand_remove(struct platform_device *pdev) ...@@ -969,22 +935,8 @@ static int fsmc_nand_remove(struct platform_device *pdev)
nand_release(&host->mtd); nand_release(&host->mtd);
clk_disable(host->clk); clk_disable(host->clk);
clk_put(host->clk); clk_put(host->clk);
iounmap(host->regs_va);
release_mem_region(host->resregs->start,
resource_size(host->resregs));
iounmap(host->cmd_va);
release_mem_region(host->rescmd->start,
resource_size(host->rescmd));
iounmap(host->addr_va);
release_mem_region(host->resaddr->start,
resource_size(host->resaddr));
iounmap(host->data_va);
release_mem_region(host->resdata->start,
resource_size(host->resdata));
kfree(host);
} }
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