Skip to content

Commit

Permalink
mtd: physmap_of: fix potential NULL dereference
Browse files Browse the repository at this point in the history
On device remove, when testing the cmtd field of an of_flash
struct to decide whether it is a concatenated device or not,
we get a false positive on cmtd == NULL, and dereference it
subsequently. This may occur if of_flash_remove() is called
from the cleanup path of of_flash_probe().

Instead, test for NULL first, and only then perform the test
for a concatenated device.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
  • Loading branch information
Ard Biesheuvel authored and Brian Norris committed Dec 13, 2014
1 parent 58c8195 commit 92b633a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions drivers/mtd/maps/physmap_of.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ static int of_flash_remove(struct platform_device *dev)
return 0;
dev_set_drvdata(&dev->dev, NULL);

if (info->cmtd != info->list[0].mtd) {
if (info->cmtd) {
mtd_device_unregister(info->cmtd);
mtd_concat_destroy(info->cmtd);
if (info->cmtd != info->list[0].mtd)
mtd_concat_destroy(info->cmtd);
}

if (info->cmtd)
mtd_device_unregister(info->cmtd);

for (i = 0; i < info->list_size; i++) {
if (info->list[i].mtd)
map_destroy(info->list[i].mtd);
Expand Down

0 comments on commit 92b633a

Please sign in to comment.