mtd: rawnand: meson: fix a loop in meson_nand_bch_mode()
Subsystems (5)
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.
--- drivers/mtd/nand/raw/meson_nand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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++) {if (meson_ecc[i].strength = nand->ecc.strength) { meson_chip->bch_mode = meson_ecc[i].bch;return 0 ;
Signature · 1 line
2.17.1
Quoted 15 lines · Dan Carpenter
There is a
sizeof()vsARRAY_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")Signed-off-by Dan Carpenter <[email protected]>--- drivers/mtd/nand/raw/meson_nand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/mtd/nand/raw/meson_nand.c +0
-0
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
-0if (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/