Skip to contentSkip to conversation

mtd: rawnand: meson: fix a loop in meson_nand_bch_mode()

PATCH In review Dan Carpenter 2 participants 2 messages Feb 1, 2019 – Feb 2, 2019

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

PATCH 2/3 mtd: rawnand: meson: fix a loop in meson_nand_bch_mode()

There is a sizeof() vs ARRAY_SIZE() bug here. We want the number of elements in the array, not the number of bytes. It means we potentially read beyond the end of the array.

Fixes 2d570b34b41a ("mtd: rawnand: meson: add support for Amlogic NAND flash controller")
---
 drivers/mtd/nand/raw/meson_nand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/meson_nand.c +1 -1
index 94c90be7e1e0..0d93d0b9c1af 100644
@@ -1143,7 +1143,7 @@ static int meson_nand_bch_mode(struct nand_chip *nand)
 	if (nand->ecc.strength > 60 || nand->ecc.strength < 8)
 		return -EINVAL;
 
-	for (i = 0; i < sizeof(meson_ecc); i++) {
+	for (i = 0; i < ARRAY_SIZE(meson_ecc); i++) {
 		if (meson_ecc[i].strength = nand->ecc.strength) {
 			meson_chip->bch_mode = meson_ecc[i].bch;
 			return 0;
Signature · 1 line
2.17.1
maintainer Acked-by on v1 2/3
#1 lore raw
Quoted 15 lines · Dan Carpenter

There is a sizeof() vs ARRAY_SIZE() bug here. We want the number of elements in the array, not the number of bytes. It means we potentially read beyond the end of the array.

Fixes 2d570b34b41a ("mtd: rawnand: meson: add support for Amlogic NAND flash controller")
---
  drivers/mtd/nand/raw/meson_nand.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/meson_nand.c +0 -0
index 94c90be7e1e0..0d93d0b9c1af 100644

drivers/mtd/nand/raw/meson_nand.c static int meson_nand_bch_mode(struct nand_chip *nand) · line 1146

Quoted 5 lines
drivers/mtd/nand/raw/meson_nand.c +1 -1
@@ -1143,7 +1143,7 @@ static int meson_nand_bch_mode(struct nand_chip *nand)
  	if (nand->ecc.strength > 60 || nand->ecc.strength < 8)
  		return -EINVAL;
 
-	for (i = 0; i < sizeof(meson_ecc); i++) {
+	for (i = 0; i < ARRAY_SIZE(meson_ecc); i++) {

ok.

drivers/mtd/nand/raw/meson_nand.c static int meson_nand_bch_mode(struct nand_chip *nand) · line 1149

Quoted 4 lines
drivers/mtd/nand/raw/meson_nand.c +0 -0
  		if (meson_ecc[i].strength == nand->ecc.strength) {
  			meson_chip->bch_mode = meson_ecc[i].bch;
  			return 0;

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/