Skip to content

Commit 3136e90

Browse files
atsushi-nemotoDavid Woodhouse
authored andcommitted
[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>
1 parent 7854643 commit 3136e90

1 file changed

Lines changed: 9 additions & 17 deletions

File tree

‎drivers/mtd/maps/physmap.c‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@
1919
#include <linux/mtd/partitions.h>
2020
#include <linux/mtd/physmap.h>
2121
#include <linux/mtd/concat.h>
22-
#include <asm/io.h>
22+
#include <linux/io.h>
2323

2424
#define MAX_RESOURCES 4
2525

2626
struct physmap_flash_info {
2727
struct mtd_info *mtd[MAX_RESOURCES];
2828
struct mtd_info *cmtd;
2929
struct map_info map[MAX_RESOURCES];
30-
struct resource *res;
3130
#ifdef CONFIG_MTD_PARTITIONS
3231
int nr_parts;
3332
struct mtd_partition *parts;
@@ -70,16 +69,7 @@ static int physmap_flash_remove(struct platform_device *dev)
7069
#endif
7170
map_destroy(info->mtd[i]);
7271
}
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);
8172
}
82-
8373
return 0;
8474
}
8575

@@ -101,7 +91,8 @@ static int physmap_flash_probe(struct platform_device *dev)
10191
if (physmap_data == NULL)
10292
return -ENODEV;
10393

104-
info = kzalloc(sizeof(struct physmap_flash_info), GFP_KERNEL);
94+
info = devm_kzalloc(&dev->dev, sizeof(struct physmap_flash_info),
95+
GFP_KERNEL);
10596
if (info == NULL) {
10697
err = -ENOMEM;
10798
goto err_out;
@@ -114,10 +105,10 @@ static int physmap_flash_probe(struct platform_device *dev)
114105
(unsigned long long)(dev->resource[i].end - dev->resource[i].start + 1),
115106
(unsigned long long)dev->resource[i].start);
116107

117-
info->res = request_mem_region(dev->resource[i].start,
118-
dev->resource[i].end - dev->resource[i].start + 1,
119-
dev->dev.bus_id);
120-
if (info->res == NULL) {
108+
if (!devm_request_mem_region(&dev->dev,
109+
dev->resource[i].start,
110+
dev->resource[i].end - dev->resource[i].start + 1,
111+
dev->dev.bus_id)) {
121112
dev_err(&dev->dev, "Could not reserve memory region\n");
122113
err = -ENOMEM;
123114
goto err_out;
@@ -129,7 +120,8 @@ static int physmap_flash_probe(struct platform_device *dev)
129120
info->map[i].bankwidth = physmap_data->width;
130121
info->map[i].set_vpp = physmap_data->set_vpp;
131122

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);
133125
if (info->map[i].virt == NULL) {
134126
dev_err(&dev->dev, "Failed to ioremap flash region\n");
135127
err = EIO;

0 commit comments

Comments
 (0)