Skip to contentSkip to conversation

mtd/m25p80: fix test for end of loop

PATCH In review Dan Carpenter 2 participants 2 messages Aug 12, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 mtd/m25p80: fix test for end of loop

"plat_id" is always non-NULL here. There is a zero element on the end of the m25p_ids[] array and if we hit the end of the loop then plat_id points to that.

This would lead to a NULL pointer dereference later on in the function.

drivers/mtd/devices/m25p80.c +1 -1
index 83c9086..6f512b5 100644
@@ -793,7 +793,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
 			break;
 		}
 
-		if (plat_id)
+		if (i < ARRAY_SIZE(m25p_ids) - 1)
 			id = plat_id;
 		else
 			dev_warn(&spi->dev, "unrecognized id %s\n", data->type);
Acked-by on v1 2/2
#1 lore raw
Quoted 7 lines · Dan Carpenter

"plat_id" is always non-NULL here. There is a zero element on the end of the m25p_ids[] array and if we hit the end of the loop then plat_id points to that.

This would lead to a NULL pointer dereference later on in the function.

Thanks,

Quoted 13 lines
drivers/mtd/devices/m25p80.c +1 -1
index 83c9086..6f512b5 100644
@@ -793,7 +793,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
 			break;
 		}
 
-		if (plat_id)
+		if (i < ARRAY_SIZE(m25p_ids) - 1)
 			id = plat_id;
 		else
 			dev_warn(&spi->dev, "unrecognized id %s\n", data->type);
Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2