Skip to content

Commit 176bf2e

Browse files
atsushi-nemotoDavid Woodhouse
authored andcommitted
[MTD] physmap: fix leak of memory returned by parse_mtd_partitions
The mtd partition parser returns an allocated pointer array of mtd_partition. The caller must free it. The array is used only for add_mtd_partitions(), so free it just after the call. Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Cc: Mike Frysinger <vapier.adi@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 002f6aa commit 176bf2e

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

‎drivers/mtd/maps/physmap.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ struct physmap_flash_info {
2929
struct map_info map[MAX_RESOURCES];
3030
#ifdef CONFIG_MTD_PARTITIONS
3131
int nr_parts;
32-
struct mtd_partition *parts;
3332
#endif
3433
};
3534

@@ -56,14 +55,10 @@ static int physmap_flash_remove(struct platform_device *dev)
5655
for (i = 0; i < MAX_RESOURCES; i++) {
5756
if (info->mtd[i] != NULL) {
5857
#ifdef CONFIG_MTD_PARTITIONS
59-
if (info->nr_parts) {
58+
if (info->nr_parts || physmap_data->nr_parts)
6059
del_mtd_partitions(info->mtd[i]);
61-
kfree(info->parts);
62-
} else if (physmap_data->nr_parts) {
63-
del_mtd_partitions(info->mtd[i]);
64-
} else {
60+
else
6561
del_mtd_device(info->mtd[i]);
66-
}
6762
#else
6863
del_mtd_device(info->mtd[i]);
6964
#endif
@@ -86,6 +81,9 @@ static int physmap_flash_probe(struct platform_device *dev)
8681
int err = 0;
8782
int i;
8883
int devices_found = 0;
84+
#ifdef CONFIG_MTD_PARTITIONS
85+
struct mtd_partition *parts;
86+
#endif
8987

9088
physmap_data = dev->dev.platform_data;
9189
if (physmap_data == NULL)
@@ -163,9 +161,10 @@ static int physmap_flash_probe(struct platform_device *dev)
163161
goto err_out;
164162

165163
#ifdef CONFIG_MTD_PARTITIONS
166-
err = parse_mtd_partitions(info->cmtd, part_probe_types, &info->parts, 0);
164+
err = parse_mtd_partitions(info->cmtd, part_probe_types, &parts, 0);
167165
if (err > 0) {
168-
add_mtd_partitions(info->cmtd, info->parts, err);
166+
add_mtd_partitions(info->cmtd, parts, err);
167+
kfree(parts);
169168
return 0;
170169
}
171170

0 commit comments

Comments
 (0)