diff options
| author | Atsushi Nemoto <anemo@mba.ocn.ne.jp> | 2008-11-26 05:26:29 -0500 |
|---|---|---|
| committer | David Woodhouse <David.Woodhouse@intel.com> | 2008-11-26 05:26:29 -0500 |
| commit | 3136e903fa2d493ebc1b8a8fbdde2d3a17f85acd (patch) | |
| tree | c118e957169be1b33325d704fa143417c6e4ff8d | |
| parent | 7854643a91eade84112dca9768eeb8d32463d101 (diff) | |
[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>
| -rw-r--r-- | drivers/mtd/maps/physmap.c | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c index 42d844f8f6bf..dfbf3f270cea 100644 --- a/drivers/mtd/maps/physmap.c +++ b/drivers/mtd/maps/physmap.c | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | #include <linux/mtd/partitions.h> | 19 | #include <linux/mtd/partitions.h> |
| 20 | #include <linux/mtd/physmap.h> | 20 | #include <linux/mtd/physmap.h> |
| 21 | #include <linux/mtd/concat.h> | 21 | #include <linux/mtd/concat.h> |
| 22 | #include <asm/io.h> | 22 | #include <linux/io.h> |
| 23 | 23 | ||
| 24 | #define MAX_RESOURCES 4 | 24 | #define MAX_RESOURCES 4 |
| 25 | 25 | ||
| @@ -27,7 +27,6 @@ struct physmap_flash_info { | |||
| 27 | struct mtd_info *mtd[MAX_RESOURCES]; | 27 | struct mtd_info *mtd[MAX_RESOURCES]; |
| 28 | struct mtd_info *cmtd; | 28 | struct mtd_info *cmtd; |
| 29 | struct map_info map[MAX_RESOURCES]; | 29 | struct map_info map[MAX_RESOURCES]; |
| 30 | struct resource *res; | ||
| 31 | #ifdef CONFIG_MTD_PARTITIONS | 30 | #ifdef CONFIG_MTD_PARTITIONS |
| 32 | int nr_parts; | 31 | int nr_parts; |
| 33 | struct mtd_partition *parts; | 32 | struct mtd_partition *parts; |
| @@ -70,16 +69,7 @@ static int physmap_flash_remove(struct platform_device *dev) | |||
| 70 | #endif | 69 | #endif |
| 71 | map_destroy(info->mtd[i]); | 70 | map_destroy(info->mtd[i]); |
| 72 | } | 71 | } |
| 73 | |||
| 74 | if (info->map[i].virt != NULL) | ||
| 75 | iounmap(info->map[i].virt); | ||
| 76 | } | ||
| 77 | |||
| 78 | if (info->res != NULL) { | ||
| 79 | release_resource(info->res); | ||
| 80 | kfree(info->res); | ||
| 81 | } | 72 | } |
| 82 | |||
| 83 | return 0; | 73 | return 0; |
| 84 | } | 74 | } |
| 85 | 75 | ||
| @@ -101,7 +91,8 @@ static int physmap_flash_probe(struct platform_device *dev) | |||
| 101 | if (physmap_data == NULL) | 91 | if (physmap_data == NULL) |
| 102 | return -ENODEV; | 92 | return -ENODEV; |
| 103 | 93 | ||
| 104 | info = kzalloc(sizeof(struct physmap_flash_info), GFP_KERNEL); | 94 | info = devm_kzalloc(&dev->dev, sizeof(struct physmap_flash_info), |
| 95 | GFP_KERNEL); | ||
| 105 | if (info == NULL) { | 96 | if (info == NULL) { |
| 106 | err = -ENOMEM; | 97 | err = -ENOMEM; |
| 107 | goto err_out; | 98 | goto err_out; |
| @@ -114,10 +105,10 @@ static int physmap_flash_probe(struct platform_device *dev) | |||
| 114 | (unsigned long long)(dev->resource[i].end - dev->resource[i].start + 1), | 105 | (unsigned long long)(dev->resource[i].end - dev->resource[i].start + 1), |
| 115 | (unsigned long long)dev->resource[i].start); | 106 | (unsigned long long)dev->resource[i].start); |
| 116 | 107 | ||
| 117 | info->res = request_mem_region(dev->resource[i].start, | 108 | if (!devm_request_mem_region(&dev->dev, |
| 118 | dev->resource[i].end - dev->resource[i].start + 1, | 109 | dev->resource[i].start, |
| 119 | dev->dev.bus_id); | 110 | dev->resource[i].end - dev->resource[i].start + 1, |
| 120 | if (info->res == NULL) { | 111 | dev->dev.bus_id)) { |
| 121 | dev_err(&dev->dev, "Could not reserve memory region\n"); | 112 | dev_err(&dev->dev, "Could not reserve memory region\n"); |
| 122 | err = -ENOMEM; | 113 | err = -ENOMEM; |
| 123 | goto err_out; | 114 | goto err_out; |
| @@ -129,7 +120,8 @@ static int physmap_flash_probe(struct platform_device *dev) | |||
| 129 | info->map[i].bankwidth = physmap_data->width; | 120 | info->map[i].bankwidth = physmap_data->width; |
| 130 | info->map[i].set_vpp = physmap_data->set_vpp; | 121 | info->map[i].set_vpp = physmap_data->set_vpp; |
| 131 | 122 | ||
| 132 | info->map[i].virt = ioremap(info->map[i].phys, info->map[i].size); | 123 | info->map[i].virt = devm_ioremap(&dev->dev, info->map[i].phys, |
| 124 | info->map[i].size); | ||
| 133 | if (info->map[i].virt == NULL) { | 125 | if (info->map[i].virt == NULL) { |
| 134 | dev_err(&dev->dev, "Failed to ioremap flash region\n"); | 126 | dev_err(&dev->dev, "Failed to ioremap flash region\n"); |
| 135 | err = EIO; | 127 | err = EIO; |
