Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Anton Vasilyev and committed by
Richard Weinberger
2e442aeb 16271224

+4 -34
+4 -34
drivers/mtd/maps/plat-ram.c
··· 43 43 struct device *dev; 44 44 struct mtd_info *mtd; 45 45 struct map_info map; 46 - struct resource *area; 47 46 struct platdata_mtd_ram *pdata; 48 47 }; 49 48 ··· 96 97 97 98 platram_setrw(info, PLATRAM_RO); 98 99 99 - /* release resources */ 100 - 101 - if (info->area) { 102 - release_resource(info->area); 103 - kfree(info->area); 104 - } 105 - 106 - if (info->map.virt != NULL) 107 - iounmap(info->map.virt); 108 - 109 100 kfree(info); 110 101 111 102 return 0; ··· 136 147 info->pdata = pdata; 137 148 138 149 /* get the resource for the memory mapping */ 139 - 140 150 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 141 - 142 - if (res == NULL) { 143 - dev_err(&pdev->dev, "no memory resource specified\n"); 144 - err = -ENOENT; 151 + info->map.virt = devm_ioremap_resource(&pdev->dev, res); 152 + if (IS_ERR(info->map.virt)) { 153 + err = PTR_ERR(info->map.virt); 154 + dev_err(&pdev->dev, "failed to ioremap() region\n"); 145 155 goto exit_free; 146 156 } 147 157 ··· 155 167 (char *)pdata->mapname : (char *)pdev->name; 156 168 info->map.bankwidth = pdata->bankwidth; 157 169 158 - /* register our usage of the memory area */ 159 - 160 - info->area = request_mem_region(res->start, info->map.size, pdev->name); 161 - if (info->area == NULL) { 162 - dev_err(&pdev->dev, "failed to request memory region\n"); 163 - err = -EIO; 164 - goto exit_free; 165 - } 166 - 167 - /* remap the memory area */ 168 - 169 - info->map.virt = ioremap(res->start, info->map.size); 170 170 dev_dbg(&pdev->dev, "virt %p, %lu bytes\n", info->map.virt, info->map.size); 171 - 172 - if (info->map.virt == NULL) { 173 - dev_err(&pdev->dev, "failed to ioremap() region\n"); 174 - err = -EIO; 175 - goto exit_free; 176 - } 177 171 178 172 simple_map_init(&info->map); 179 173