[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>
This commit is contained in:
parent
7854643a91
commit
3136e903fa
1 changed files with 9 additions and 17 deletions
|
@ -19,7 +19,7 @@
|
||||||
#include <linux/mtd/partitions.h>
|
#include <linux/mtd/partitions.h>
|
||||||
#include <linux/mtd/physmap.h>
|
#include <linux/mtd/physmap.h>
|
||||||
#include <linux/mtd/concat.h>
|
#include <linux/mtd/concat.h>
|
||||||
#include <asm/io.h>
|
#include <linux/io.h>
|
||||||
|
|
||||||
#define MAX_RESOURCES 4
|
#define MAX_RESOURCES 4
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ struct physmap_flash_info {
|
||||||
struct mtd_info *mtd[MAX_RESOURCES];
|
struct mtd_info *mtd[MAX_RESOURCES];
|
||||||
struct mtd_info *cmtd;
|
struct mtd_info *cmtd;
|
||||||
struct map_info map[MAX_RESOURCES];
|
struct map_info map[MAX_RESOURCES];
|
||||||
struct resource *res;
|
|
||||||
#ifdef CONFIG_MTD_PARTITIONS
|
#ifdef CONFIG_MTD_PARTITIONS
|
||||||
int nr_parts;
|
int nr_parts;
|
||||||
struct mtd_partition *parts;
|
struct mtd_partition *parts;
|
||||||
|
@ -70,16 +69,7 @@ static int physmap_flash_remove(struct platform_device *dev)
|
||||||
#endif
|
#endif
|
||||||
map_destroy(info->mtd[i]);
|
map_destroy(info->mtd[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->map[i].virt != NULL)
|
|
||||||
iounmap(info->map[i].virt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->res != NULL) {
|
|
||||||
release_resource(info->res);
|
|
||||||
kfree(info->res);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +91,8 @@ static int physmap_flash_probe(struct platform_device *dev)
|
||||||
if (physmap_data == NULL)
|
if (physmap_data == NULL)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
info = kzalloc(sizeof(struct physmap_flash_info), GFP_KERNEL);
|
info = devm_kzalloc(&dev->dev, sizeof(struct physmap_flash_info),
|
||||||
|
GFP_KERNEL);
|
||||||
if (info == NULL) {
|
if (info == NULL) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto err_out;
|
goto err_out;
|
||||||
|
@ -114,10 +105,10 @@ static int physmap_flash_probe(struct platform_device *dev)
|
||||||
(unsigned long long)(dev->resource[i].end - dev->resource[i].start + 1),
|
(unsigned long long)(dev->resource[i].end - dev->resource[i].start + 1),
|
||||||
(unsigned long long)dev->resource[i].start);
|
(unsigned long long)dev->resource[i].start);
|
||||||
|
|
||||||
info->res = request_mem_region(dev->resource[i].start,
|
if (!devm_request_mem_region(&dev->dev,
|
||||||
dev->resource[i].end - dev->resource[i].start + 1,
|
dev->resource[i].start,
|
||||||
dev->dev.bus_id);
|
dev->resource[i].end - dev->resource[i].start + 1,
|
||||||
if (info->res == NULL) {
|
dev->dev.bus_id)) {
|
||||||
dev_err(&dev->dev, "Could not reserve memory region\n");
|
dev_err(&dev->dev, "Could not reserve memory region\n");
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto err_out;
|
goto err_out;
|
||||||
|
@ -129,7 +120,8 @@ static int physmap_flash_probe(struct platform_device *dev)
|
||||||
info->map[i].bankwidth = physmap_data->width;
|
info->map[i].bankwidth = physmap_data->width;
|
||||||
info->map[i].set_vpp = physmap_data->set_vpp;
|
info->map[i].set_vpp = physmap_data->set_vpp;
|
||||||
|
|
||||||
info->map[i].virt = ioremap(info->map[i].phys, info->map[i].size);
|
info->map[i].virt = devm_ioremap(&dev->dev, info->map[i].phys,
|
||||||
|
info->map[i].size);
|
||||||
if (info->map[i].virt == NULL) {
|
if (info->map[i].virt == NULL) {
|
||||||
dev_err(&dev->dev, "Failed to ioremap flash region\n");
|
dev_err(&dev->dev, "Failed to ioremap flash region\n");
|
||||||
err = EIO;
|
err = EIO;
|
||||||
|
|
Loading…
Reference in a new issue