[MTD] physmap: fix memory leak on physmap_flash_remove by using devres

physmap_flash_remove releases only last memory region. This causes
memory leak if multiple resources were provided.

This patch fixes this leakage by using devm_ functions.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>

authored by Atsushi Nemoto and committed by David Woodhouse 3136e903 7854643a

+9 -17
+9 -17
drivers/mtd/maps/physmap.c
··· 19 19 #include <linux/mtd/partitions.h> 20 20 #include <linux/mtd/physmap.h> 21 21 #include <linux/mtd/concat.h> 22 - #include <asm/io.h> 22 + #include <linux/io.h> 23 23 24 24 #define MAX_RESOURCES 4 25 25 ··· 27 27 struct mtd_info *mtd[MAX_RESOURCES]; 28 28 struct mtd_info *cmtd; 29 29 struct map_info map[MAX_RESOURCES]; 30 - struct resource *res; 31 30 #ifdef CONFIG_MTD_PARTITIONS 32 31 int nr_parts; 33 32 struct mtd_partition *parts; ··· 69 70 #endif 70 71 map_destroy(info->mtd[i]); 71 72 } 72 - 73 - if (info->map[i].virt != NULL) 74 - iounmap(info->map[i].virt); 75 73 } 76 - 77 - if (info->res != NULL) { 78 - release_resource(info->res); 79 - kfree(info->res); 80 - } 81 - 82 74 return 0; 83 75 } 84 76 ··· 91 101 if (physmap_data == NULL) 92 102 return -ENODEV; 93 103 94 - info = kzalloc(sizeof(struct physmap_flash_info), GFP_KERNEL); 104 + info = devm_kzalloc(&dev->dev, sizeof(struct physmap_flash_info), 105 + GFP_KERNEL); 95 106 if (info == NULL) { 96 107 err = -ENOMEM; 97 108 goto err_out; ··· 105 114 (unsigned long long)(dev->resource[i].end - dev->resource[i].start + 1), 106 115 (unsigned long long)dev->resource[i].start); 107 116 108 - info->res = request_mem_region(dev->resource[i].start, 109 - dev->resource[i].end - dev->resource[i].start + 1, 110 - dev->dev.bus_id); 111 - if (info->res == NULL) { 117 + if (!devm_request_mem_region(&dev->dev, 118 + dev->resource[i].start, 119 + dev->resource[i].end - dev->resource[i].start + 1, 120 + dev->dev.bus_id)) { 112 121 dev_err(&dev->dev, "Could not reserve memory region\n"); 113 122 err = -ENOMEM; 114 123 goto err_out; ··· 120 129 info->map[i].bankwidth = physmap_data->width; 121 130 info->map[i].set_vpp = physmap_data->set_vpp; 122 131 123 - info->map[i].virt = ioremap(info->map[i].phys, info->map[i].size); 132 + info->map[i].virt = devm_ioremap(&dev->dev, info->map[i].phys, 133 + info->map[i].size); 124 134 if (info->map[i].virt == NULL) { 125 135 dev_err(&dev->dev, "Failed to ioremap flash region\n"); 126 136 err = EIO;