nand: davinci: avoid out of bounds array access
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Tue, 30 Jul 2019 21:29:21 +0000 (23:29 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 31 Jul 2019 17:08:07 +0000 (13:08 -0400)
The array bounds have to be checked before accessing the array element.

Identified by cppcheck.

Fixes: 67ac6ffaeefb ("mtd: nand: davinci: add opportunity to write keystone U-boot image")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
drivers/mtd/nand/raw/davinci_nand.c

index 33c2f16be8bd9d2d0848c78d82b9bc5fe9346ef0..724bbee75263352d42b8fb9a33f2501b7be54eec 100644 (file)
@@ -739,8 +739,8 @@ static void davinci_nand_init(struct nand_chip *nand)
 
        layout = &nand_keystone_rbl_4bit_layout_oobfirst;
        layout->oobavail = 0;
-       for (i = 0; layout->oobfree[i].length &&
-            i < ARRAY_SIZE(layout->oobfree); i++)
+       for (i = 0; i < ARRAY_SIZE(layout->oobfree) &&
+            layout->oobfree[i].length; i++)
                layout->oobavail += layout->oobfree[i].length;
 
        nand->write_page = nand_davinci_write_page;