public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tao Hou <hotforest@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] mtd: nand: use ssize_t instead of size_t to prevent infinite loop
Date: Sat,  2 Mar 2013 17:00:34 +0800	[thread overview]
Message-ID: <1362214834-7309-1-git-send-email-hotforest@gmail.com> (raw)

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.

Signed-off-by: Tao Hou <hotforest@gmail.com>
Cc: Ben Gardiner <bengardiner@nanometrics.ca>
Cc: Scott Wood <scottwood@freescale.com>
---
 drivers/mtd/nand/nand_util.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c
index ff2d348..de1d13e 100644
--- a/drivers/mtd/nand/nand_util.c
+++ b/drivers/mtd/nand/nand_util.c
@@ -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)
-- 
1.7.9.5

             reply	other threads:[~2013-03-02  9:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-02  9:00 Tao Hou [this message]
2013-05-22 21:51 ` [U-Boot] mtd: nand: use ssize_t instead of size_t to prevent infinite loop Scott Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362214834-7309-1-git-send-email-hotforest@gmail.com \
    --to=hotforest@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox