Commit 8ce110ac authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by David Woodhouse

mtd: Fix compile failure and error path in physmap.c

Commit 4b56ffca ("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: default avatarAtsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent 1cc52399
...@@ -44,12 +44,10 @@ static int physmap_flash_remove(struct platform_device *dev) ...@@ -44,12 +44,10 @@ static int physmap_flash_remove(struct platform_device *dev)
return 0; return 0;
platform_set_drvdata(dev, NULL); platform_set_drvdata(dev, NULL);
if (info->cmtd == NULL)
return 0;
physmap_data = dev->dev.platform_data; 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) { if (info->nr_parts || physmap_data->nr_parts) {
del_mtd_partitions(info->cmtd); del_mtd_partitions(info->cmtd);
...@@ -58,14 +56,14 @@ static int physmap_flash_remove(struct platform_device *dev) ...@@ -58,14 +56,14 @@ static int physmap_flash_remove(struct platform_device *dev)
} else { } else {
del_mtd_device(info->cmtd); del_mtd_device(info->cmtd);
} }
} else { #else
del_mtd_device(info->cmtd); del_mtd_device(info->cmtd);
} #endif
#ifdef CONFIG_MTD_CONCAT #ifdef CONFIG_MTD_CONCAT
if (info->cmtd != info->mtd[0]) if (info->cmtd != info->mtd[0])
mtd_concat_destroy(info->cmtd); mtd_concat_destroy(info->cmtd);
#endif #endif
}
for (i = 0; i < MAX_RESOURCES; i++) { for (i = 0; i < MAX_RESOURCES; i++) {
if (info->mtd[i] != NULL) if (info->mtd[i] != NULL)
...@@ -170,7 +168,7 @@ static int physmap_flash_probe(struct platform_device *dev) ...@@ -170,7 +168,7 @@ static int physmap_flash_probe(struct platform_device *dev)
if (err) if (err)
goto err_out; goto err_out;
if (mtd_has_partitions()) { #ifdef CONFIG_MTD_PARTITIONS
err = parse_mtd_partitions(info->cmtd, part_probe_types, err = parse_mtd_partitions(info->cmtd, part_probe_types,
&info->parts, 0); &info->parts, 0);
if (err > 0) { if (err > 0) {
...@@ -185,7 +183,7 @@ static int physmap_flash_probe(struct platform_device *dev) ...@@ -185,7 +183,7 @@ static int physmap_flash_probe(struct platform_device *dev)
physmap_data->nr_parts); physmap_data->nr_parts);
return 0; return 0;
} }
} #endif
add_mtd_device(info->cmtd); add_mtd_device(info->cmtd);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment