Skip to content

Commit 4b56ffc

Browse files
H Hartley SweetenDavid Woodhouse
authored andcommitted
mtd: Fix kernel NULL pointer dereference in physmap.c
During the probe for physmap platform flash devices there are a number error exit conditions that all do a goto err_out which then calls physmap_flash_remove(). In that function one of the cleanup steps is: #ifdef CONFIG_MTD_CONCAT if (info->cmtd != info->mtd[0]) mtd_concat_destroy(info->cmtd); #endif This test will succeed since info->cmtd == NULL and info->mtd[0] is valid. Fix this by exiting the remove function when info->cmtd == NULL. Also, cleanup the #ifdef CONFIG_MTD_PARTITIONS stuff by using mtd_has_partitions(). Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 2d098a7 commit 4b56ffc

1 file changed

Lines changed: 25 additions & 24 deletions

File tree

‎drivers/mtd/maps/physmap.c‎

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,23 @@ 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+
4750
physmap_data = dev->dev.platform_data;
4851

49-
if (info->cmtd) {
50-
#ifdef CONFIG_MTD_PARTITIONS
51-
if (info->nr_parts || physmap_data->nr_parts)
52+
if (mtd_has_partitions()) {
53+
if (info->nr_parts || physmap_data->nr_parts) {
5254
del_mtd_partitions(info->cmtd);
53-
else
55+
56+
if (info->nr_parts)
57+
kfree(info->parts);
58+
} else {
5459
del_mtd_device(info->cmtd);
55-
#else
60+
}
61+
} else {
5662
del_mtd_device(info->cmtd);
57-
#endif
5863
}
59-
#ifdef CONFIG_MTD_PARTITIONS
60-
if (info->nr_parts)
61-
kfree(info->parts);
62-
#endif
6364

6465
#ifdef CONFIG_MTD_CONCAT
6566
if (info->cmtd != info->mtd[0])
@@ -169,22 +170,22 @@ static int physmap_flash_probe(struct platform_device *dev)
169170
if (err)
170171
goto err_out;
171172

172-
#ifdef CONFIG_MTD_PARTITIONS
173-
err = parse_mtd_partitions(info->cmtd, part_probe_types,
174-
&info->parts, 0);
175-
if (err > 0) {
176-
add_mtd_partitions(info->cmtd, info->parts, err);
177-
info->nr_parts = err;
178-
return 0;
179-
}
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+
}
180181

181-
if (physmap_data->nr_parts) {
182-
printk(KERN_NOTICE "Using physmap partition information\n");
183-
add_mtd_partitions(info->cmtd, physmap_data->parts,
184-
physmap_data->nr_parts);
185-
return 0;
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+
}
186188
}
187-
#endif
188189

189190
add_mtd_device(info->cmtd);
190191
return 0;

0 commit comments

Comments
 (0)