Skip to content

Commit

Permalink
mtd: Fix compile failure and error path in physmap.c
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
H Hartley Sweeten authored and David Woodhouse committed Oct 20, 2009
1 parent 1cc5239 commit 8ce110a
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions drivers/mtd/maps/physmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ static int physmap_flash_remove(struct platform_device *dev)
return 0;
platform_set_drvdata(dev, NULL);

if (info->cmtd == NULL)
return 0;

physmap_data = dev->dev.platform_data;

if (mtd_has_partitions()) {
if (info->cmtd) {
#ifdef CONFIG_MTD_PARTITIONS
if (info->nr_parts || physmap_data->nr_parts) {
del_mtd_partitions(info->cmtd);

Expand All @@ -58,14 +56,14 @@ static int physmap_flash_remove(struct platform_device *dev)
} else {
del_mtd_device(info->cmtd);
}
} else {
#else
del_mtd_device(info->cmtd);
}

#endif
#ifdef CONFIG_MTD_CONCAT
if (info->cmtd != info->mtd[0])
mtd_concat_destroy(info->cmtd);
if (info->cmtd != info->mtd[0])
mtd_concat_destroy(info->cmtd);
#endif
}

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

if (mtd_has_partitions()) {
err = parse_mtd_partitions(info->cmtd, part_probe_types,
&info->parts, 0);
if (err > 0) {
add_mtd_partitions(info->cmtd, info->parts, err);
info->nr_parts = err;
return 0;
}
#ifdef CONFIG_MTD_PARTITIONS
err = parse_mtd_partitions(info->cmtd, part_probe_types,
&info->parts, 0);
if (err > 0) {
add_mtd_partitions(info->cmtd, info->parts, err);
info->nr_parts = err;
return 0;
}

if (physmap_data->nr_parts) {
printk(KERN_NOTICE "Using physmap partition information\n");
add_mtd_partitions(info->cmtd, physmap_data->parts,
physmap_data->nr_parts);
return 0;
}
if (physmap_data->nr_parts) {
printk(KERN_NOTICE "Using physmap partition information\n");
add_mtd_partitions(info->cmtd, physmap_data->parts,
physmap_data->nr_parts);
return 0;
}
#endif

add_mtd_device(info->cmtd);
return 0;
Expand Down

0 comments on commit 8ce110a

Please sign in to comment.