Skip to content

Commit

Permalink
mtd: physmap_of: error checking to prevent a NULL pointer dereference
Browse files Browse the repository at this point in the history
This patch solves a NULL pointer dereference, this may occur if the tuple
is not mappable (jumps to continue in the for-loop). Out of the loop
possible results are:
- info->list_size == 0  if no of the tuples is mappable
- info->list_size == 1
- info->list_size > 1
If no one of the supplied tuples is mappable (info->list_size == 0) and
info->cmtd will not be set. But it is used in mtd_device_parse_register, OOPS!
actually it should generate an error in this case!

Signed-off-by: Anton Prins <anton.prins@nl.bosch.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
  • Loading branch information
Anton Prins authored and Artem Bityutskiy committed Dec 10, 2012
1 parent 6c810f9 commit e58a66d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/mtd/maps/physmap_of.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ static int of_flash_probe(struct platform_device *dev)
}

err = 0;
info->cmtd = NULL;
if (info->list_size == 1) {
info->cmtd = info->list[0].mtd;
} else if (info->list_size > 1) {
Expand All @@ -293,9 +294,10 @@ static int of_flash_probe(struct platform_device *dev)
*/
info->cmtd = mtd_concat_create(mtd_list, info->list_size,
dev_name(&dev->dev));
if (info->cmtd == NULL)
err = -ENXIO;
}
if (info->cmtd == NULL)
err = -ENXIO;

if (err)
goto err_out;

Expand Down

0 comments on commit e58a66d

Please sign in to comment.