diff options
author | H Hartley Sweeten <hartleys@visionengravers.com> | 2009-10-20 12:23:33 -0400 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2009-10-20 17:29:27 -0400 |
commit | 8ce110ac19bc88b82e3feacfbb3a2ee08a07fe22 (patch) | |
tree | 942c3de936655fb78a9e356a4cea6b056687c7da /drivers/mtd/maps | |
parent | 1cc523999e0acd0c21f83bf89b7a44b4ab6f7bd8 (diff) |
mtd: Fix compile failure and error path in physmap.c
Commit 4b56ffcacee937a85bf39e14872dd141e23ee85f ("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>
Diffstat (limited to 'drivers/mtd/maps')
-rw-r--r-- | drivers/mtd/maps/physmap.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c index 65f52d4804a..3f13a9673e7 100644 --- a/drivers/mtd/maps/physmap.c +++ b/drivers/mtd/maps/physmap.c | |||
@@ -44,12 +44,10 @@ static int physmap_flash_remove(struct platform_device *dev) | |||
44 | return 0; | 44 | return 0; |
45 | platform_set_drvdata(dev, NULL); | 45 | platform_set_drvdata(dev, NULL); |
46 | 46 | ||
47 | if (info->cmtd == NULL) | ||
48 | return 0; | ||
49 | |||
50 | physmap_data = dev->dev.platform_data; | 47 | physmap_data = dev->dev.platform_data; |
51 | 48 | ||
52 | if (mtd_has_partitions()) { | 49 | if (info->cmtd) { |
50 | #ifdef CONFIG_MTD_PARTITIONS | ||
53 | if (info->nr_parts || physmap_data->nr_parts) { | 51 | if (info->nr_parts || physmap_data->nr_parts) { |
54 | del_mtd_partitions(info->cmtd); | 52 | del_mtd_partitions(info->cmtd); |
55 | 53 | ||
@@ -58,14 +56,14 @@ static int physmap_flash_remove(struct platform_device *dev) | |||
58 | } else { | 56 | } else { |
59 | del_mtd_device(info->cmtd); | 57 | del_mtd_device(info->cmtd); |
60 | } | 58 | } |
61 | } else { | 59 | #else |
62 | del_mtd_device(info->cmtd); | 60 | del_mtd_device(info->cmtd); |
63 | } | 61 | #endif |
64 | |||
65 | #ifdef CONFIG_MTD_CONCAT | 62 | #ifdef CONFIG_MTD_CONCAT |
66 | if (info->cmtd != info->mtd[0]) | 63 | if (info->cmtd != info->mtd[0]) |
67 | mtd_concat_destroy(info->cmtd); | 64 | mtd_concat_destroy(info->cmtd); |
68 | #endif | 65 | #endif |
66 | } | ||
69 | 67 | ||
70 | for (i = 0; i < MAX_RESOURCES; i++) { | 68 | for (i = 0; i < MAX_RESOURCES; i++) { |
71 | if (info->mtd[i] != NULL) | 69 | if (info->mtd[i] != NULL) |
@@ -170,22 +168,22 @@ static int physmap_flash_probe(struct platform_device *dev) | |||
170 | if (err) | 168 | if (err) |
171 | goto err_out; | 169 | goto err_out; |
172 | 170 | ||
173 | if (mtd_has_partitions()) { | 171 | #ifdef CONFIG_MTD_PARTITIONS |
174 | err = parse_mtd_partitions(info->cmtd, part_probe_types, | 172 | err = parse_mtd_partitions(info->cmtd, part_probe_types, |
175 | &info->parts, 0); | 173 | &info->parts, 0); |
176 | if (err > 0) { | 174 | if (err > 0) { |
177 | add_mtd_partitions(info->cmtd, info->parts, err); | 175 | add_mtd_partitions(info->cmtd, info->parts, err); |
178 | info->nr_parts = err; | 176 | info->nr_parts = err; |
179 | return 0; | 177 | return 0; |
180 | } | 178 | } |
181 | 179 | ||
182 | if (physmap_data->nr_parts) { | 180 | if (physmap_data->nr_parts) { |
183 | printk(KERN_NOTICE "Using physmap partition information\n"); | 181 | printk(KERN_NOTICE "Using physmap partition information\n"); |
184 | add_mtd_partitions(info->cmtd, physmap_data->parts, | 182 | add_mtd_partitions(info->cmtd, physmap_data->parts, |
185 | physmap_data->nr_parts); | 183 | physmap_data->nr_parts); |
186 | return 0; | 184 | return 0; |
187 | } | ||
188 | } | 185 | } |
186 | #endif | ||
189 | 187 | ||
190 | add_mtd_device(info->cmtd); | 188 | add_mtd_device(info->cmtd); |
191 | return 0; | 189 | return 0; |