Skip to content

Commit 8ce110a

Browse files
H Hartley SweetenDavid Woodhouse
authored andcommitted
mtd: Fix compile failure and error path in physmap.c
Commit 4b56ffc ("mtd: Fix kernel NULL pointer dereference in physmap.c") introduced a couple of bugs. It neglected to run the loop of map_destroy() calls in physmap_flash_remove(), if !info->cmtd, which would happen if that function was called to clean up errors during probe. It also failed to compile if CONFIG_MTD_PARTITIONS was not defined. Reported-By: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 1cc5239 commit 8ce110a

1 file changed

Lines changed: 21 additions & 23 deletions

File tree

‎drivers/mtd/maps/physmap.c‎

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ static int physmap_flash_remove(struct platform_device *dev)
4444
return 0;
4545
platform_set_drvdata(dev, NULL);
4646

47-
if (info->cmtd == NULL)
48-
return 0;
49-
5047
physmap_data = dev->dev.platform_data;
5148

52-
if (mtd_has_partitions()) {
49+
if (info->cmtd) {
50+
#ifdef CONFIG_MTD_PARTITIONS
5351
if (info->nr_parts || physmap_data->nr_parts) {
5452
del_mtd_partitions(info->cmtd);
5553

@@ -58,14 +56,14 @@ static int physmap_flash_remove(struct platform_device *dev)
5856
} else {
5957
del_mtd_device(info->cmtd);
6058
}
61-
} else {
59+
#else
6260
del_mtd_device(info->cmtd);
63-
}
64-
61+
#endif
6562
#ifdef CONFIG_MTD_CONCAT
66-
if (info->cmtd != info->mtd[0])
67-
mtd_concat_destroy(info->cmtd);
63+
if (info->cmtd != info->mtd[0])
64+
mtd_concat_destroy(info->cmtd);
6865
#endif
66+
}
6967

7068
for (i = 0; i < MAX_RESOURCES; i++) {
7169
if (info->mtd[i] != NULL)
@@ -170,22 +168,22 @@ static int physmap_flash_probe(struct platform_device *dev)
170168
if (err)
171169
goto err_out;
172170

173-
if (mtd_has_partitions()) {
174-
err = parse_mtd_partitions(info->cmtd, part_probe_types,
175-
&info->parts, 0);
176-
if (err > 0) {
177-
add_mtd_partitions(info->cmtd, info->parts, err);
178-
info->nr_parts = err;
179-
return 0;
180-
}
171+
#ifdef CONFIG_MTD_PARTITIONS
172+
err = parse_mtd_partitions(info->cmtd, part_probe_types,
173+
&info->parts, 0);
174+
if (err > 0) {
175+
add_mtd_partitions(info->cmtd, info->parts, err);
176+
info->nr_parts = err;
177+
return 0;
178+
}
181179

182-
if (physmap_data->nr_parts) {
183-
printk(KERN_NOTICE "Using physmap partition information\n");
184-
add_mtd_partitions(info->cmtd, physmap_data->parts,
185-
physmap_data->nr_parts);
186-
return 0;
187-
}
180+
if (physmap_data->nr_parts) {
181+
printk(KERN_NOTICE "Using physmap partition information\n");
182+
add_mtd_partitions(info->cmtd, physmap_data->parts,
183+
physmap_data->nr_parts);
184+
return 0;
188185
}
186+
#endif
189187

190188
add_mtd_device(info->cmtd);
191189
return 0;

0 commit comments

Comments
 (0)