Skip to contentSkip to conversation

drivers/mtd/nand/cafe_ecc.c: fix an off-by-one in a BUG_ON

PATCH Applied Adrian Bunk 2 participants 2 messages Feb 2, 2007 – Feb 9, 2007

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

PATCH 1/1 drivers/mtd/nand/cafe_ecc.c: fix an off-by-one in a BUG_ON

err_pos_lut[4096] of an array with 4096 elements is a bug.

Spotted by the Coverity checker.

While I was at it, I also converted it to ARRAY_SIZE().

drivers/mtd/nand/cafe_ecc.c renamed from drivers/mtd/nand/cafe_ecc.c.old +1 -1
@@ -1045,7 +1045,7 @@
 
 static unsigned short err_pos(unsigned short din)
 {
-	BUG_ON(din > 4096);
+	BUG_ON(din >= ARRAY_SIZE(err_pos_lut));
 	return err_pos_lut[din];
 }
 static int chk_no_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
#1 lore raw
Quoted 5 lines · Adrian Bunk

err_pos_lut[4096] of an array with 4096 elements is a bug.

Spotted by the Coverity checker.

While I was at it, I also converted it to ARRAY_SIZE().

Applied; thanks.

Signature · 1 line
dwmw2