aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/maps
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2014-11-30 07:51:03 -0500
committerBrian Norris <computersforpeace@gmail.com>2014-12-12 22:12:16 -0500
commit92b633a8a482c4bc1ff3b7cffdcace7836861554 (patch)
tree7b64321201ddde6d9cd049851039156d3221a39b /drivers/mtd/maps
parent58c81957b7d284c57a9fc1b815c77155ef744ea5 (diff)
mtd: physmap_of: fix potential NULL dereference
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>
Diffstat (limited to 'drivers/mtd/maps')
-rw-r--r--drivers/mtd/maps/physmap_of.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
index c1d21cb501ca..e48930424091 100644
--- a/drivers/mtd/maps/physmap_of.c
+++ b/drivers/mtd/maps/physmap_of.c
@@ -47,14 +47,12 @@ static int of_flash_remove(struct platform_device *dev)
47 return 0; 47 return 0;
48 dev_set_drvdata(&dev->dev, NULL); 48 dev_set_drvdata(&dev->dev, NULL);
49 49
50 if (info->cmtd != info->list[0].mtd) { 50 if (info->cmtd) {
51 mtd_device_unregister(info->cmtd); 51 mtd_device_unregister(info->cmtd);
52 mtd_concat_destroy(info->cmtd); 52 if (info->cmtd != info->list[0].mtd)
53 mtd_concat_destroy(info->cmtd);
53 } 54 }
54 55
55 if (info->cmtd)
56 mtd_device_unregister(info->cmtd);
57
58 for (i = 0; i < info->list_size; i++) { 56 for (i = 0; i < info->list_size; i++) {
59 if (info->list[i].mtd) 57 if (info->list[i].mtd)
60 map_destroy(info->list[i].mtd); 58 map_destroy(info->list[i].mtd);