Skip to content

Commit

Permalink
mtd: physmap: fix NULL pointer dereference in error path
Browse files Browse the repository at this point in the history
commit e480814 ("[MTD] [MAPS] physmap:
fix wrong free and del_mtd_{partition,device}") introduces a NULL pointer
dereference in physmap_flash_remove when called from the error path in
physmap_flash_probe (if map_probe failed).

Call del_mtd_{partition,device} only if info->cmtd was not NULL.

Reported-by: pHilipp Zabel <philipp.zabel@gmail.com>
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Atsushi Nemoto authored and Linus Torvalds committed Mar 10, 2009
1 parent 9c1e8a4 commit d58ab5c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions drivers/mtd/maps/physmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,19 @@ static int physmap_flash_remove(struct platform_device *dev)

physmap_data = dev->dev.platform_data;

if (info->cmtd) {
#ifdef CONFIG_MTD_PARTITIONS
if (info->nr_parts) {
del_mtd_partitions(info->cmtd);
kfree(info->parts);
} else if (physmap_data->nr_parts)
del_mtd_partitions(info->cmtd);
else
del_mtd_device(info->cmtd);
if (info->nr_parts || physmap_data->nr_parts)
del_mtd_partitions(info->cmtd);
else
del_mtd_device(info->cmtd);
#else
del_mtd_device(info->cmtd);
del_mtd_device(info->cmtd);
#endif
}
#ifdef CONFIG_MTD_PARTITIONS
if (info->nr_parts)
kfree(info->parts);
#endif

#ifdef CONFIG_MTD_CONCAT
Expand Down

0 comments on commit d58ab5c

Please sign in to comment.