Skip to contentSkip to conversation

nand: davinci: avoid out of bounds array access

PATCH New Heinrich Schuchardt 2 participants 2 messages Jul 30, 2019 – Aug 1, 2019

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

PATCH 1/1 nand: davinci: avoid out of bounds array access

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")
---
 drivers/mtd/nand/raw/davinci_nand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/raw/davinci_nand.c +2 -2
index 33c2f16be8..724bbee752 100644
@@ -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;

--
2.20.1

#1 lore raw

PATCH 1/1 nand: davinci: avoid out of bounds array access

Quoted 6 lines · Heinrich Schuchardt

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")

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190731/7241438d/attachment.sig>