mtd: plat-ram: Replace manual resource management by devm

Driver contains unsuitable request_mem_region() and
release_resource() calls.

The patch switches manual resource management by devm interface for
readability and error-free simplification.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru>
Suggested-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
This commit is contained in:
Anton Vasilyev 2017-08-22 16:24:11 +03:00 committed by Richard Weinberger
parent 16271224bc
commit 2e442aebed
1 changed files with 4 additions and 34 deletions

View File

@ -43,7 +43,6 @@ struct platram_info {
struct device *dev; struct device *dev;
struct mtd_info *mtd; struct mtd_info *mtd;
struct map_info map; struct map_info map;
struct resource *area;
struct platdata_mtd_ram *pdata; struct platdata_mtd_ram *pdata;
}; };
@ -97,16 +96,6 @@ static int platram_remove(struct platform_device *pdev)
platram_setrw(info, PLATRAM_RO); platram_setrw(info, PLATRAM_RO);
/* release resources */
if (info->area) {
release_resource(info->area);
kfree(info->area);
}
if (info->map.virt != NULL)
iounmap(info->map.virt);
kfree(info); kfree(info);
return 0; return 0;
@ -147,12 +136,11 @@ static int platram_probe(struct platform_device *pdev)
info->pdata = pdata; info->pdata = pdata;
/* get the resource for the memory mapping */ /* get the resource for the memory mapping */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
info->map.virt = devm_ioremap_resource(&pdev->dev, res);
if (res == NULL) { if (IS_ERR(info->map.virt)) {
dev_err(&pdev->dev, "no memory resource specified\n"); err = PTR_ERR(info->map.virt);
err = -ENOENT; dev_err(&pdev->dev, "failed to ioremap() region\n");
goto exit_free; goto exit_free;
} }
@ -167,26 +155,8 @@ static int platram_probe(struct platform_device *pdev)
(char *)pdata->mapname : (char *)pdev->name; (char *)pdata->mapname : (char *)pdev->name;
info->map.bankwidth = pdata->bankwidth; info->map.bankwidth = pdata->bankwidth;
/* register our usage of the memory area */
info->area = request_mem_region(res->start, info->map.size, pdev->name);
if (info->area == NULL) {
dev_err(&pdev->dev, "failed to request memory region\n");
err = -EIO;
goto exit_free;
}
/* remap the memory area */
info->map.virt = ioremap(res->start, info->map.size);
dev_dbg(&pdev->dev, "virt %p, %lu bytes\n", info->map.virt, info->map.size); dev_dbg(&pdev->dev, "virt %p, %lu bytes\n", info->map.virt, info->map.size);
if (info->map.virt == NULL) {
dev_err(&pdev->dev, "failed to ioremap() region\n");
err = -EIO;
goto exit_free;
}
simple_map_init(&info->map); simple_map_init(&info->map);
dev_dbg(&pdev->dev, "initialised map, probing for mtd\n"); dev_dbg(&pdev->dev, "initialised map, probing for mtd\n");