Skip to contentSkip to conversation

mtd: nand: use ssize_t instead of size_t to prevent infinite loop

PATCH In review Tao Hou 2 participants 2 messages Mar 2, 2013 – May 22, 2013

Subsystems (2)
lore
Share & tools
lore

Tao Hou

author
#0 lore raw

PATCH 1/1 mtd: nand: use ssize_t instead of size_t to prevent infinite loop

When a all 0xFF buffer is passed to drop_ffs, the no-0xFF check loop will loop forever.
After the fix, If ssize_t i = -1 and size_t l = i + 1, the value of l will still be 0 as expected.

Cc Ben Gardiner <[email protected]>
Cc Scott Wood <[email protected]>
---
 drivers/mtd/nand/nand_util.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mtd/nand/nand_util.c +2 -1
index ff2d348..de1d13e 100644
@@ -451,7 +451,8 @@ static int check_skip_len(nand_info_t *nand, loff_t offset, size_t length)
 static size_t drop_ffs(const nand_info_t *nand, const u_char *buf,
 			const size_t *len)
 {
-	size_t i, l = *len;
+	size_t l = *len;
+	ssize_t i;
 
 	for (i = l - 1; i >= 0; i--)
 		if (buf[i] != 0xFF)
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 5 lines · htbegin

When a all 0xFF buffer is passed to drop_ffs, the no-0xFF check loop will loop forever.
After the fix, If ssize_t i = -1 and size_t l = i + 1, the value of l will still be 0 as expected.

Quoted 7 lines
Cc Ben Gardiner <[email protected]>
Cc Scott Wood <[email protected]>

---
drivers/mtd/nand/nand_util.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)

Applied to u-boot-nand-flash

-Scott