From: Brian Norris <computersforpeace@gmail.com>
To: <linux-mtd@lists.infradead.org>
Cc: Brian Norris <computersforpeace@gmail.com>,
Maxim Levitsky <maximlevitsky@gmail.com>
Subject: [PATCH 6/6] mtd: nand: r852: correct write_buf loop bounds
Date: Tue, 20 May 2014 23:17:03 -0700 [thread overview]
Message-ID: <1400653023-25757-7-git-send-email-computersforpeace@gmail.com> (raw)
In-Reply-To: <1400653023-25757-1-git-send-email-computersforpeace@gmail.com>
The two loops in r852_write_buf() are designed to handle 4-byte-aligned
and then 1-byte-aligned portions, respectively. However, there are two
issues:
(1) The first loop will only terminate if 'len' is a multiple of 4
(2) The second loop will never terminate if it runs at least once
Rewrite these loops as they were probably intended. Compile tested only.
Issues pointed out by Coverity Scan.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Cc: Maxim Levitsky <maximlevitsky@gmail.com>
---
drivers/mtd/nand/r852.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/nand/r852.c b/drivers/mtd/nand/r852.c
index 325930db3f04..baea83f4dea8 100644
--- a/drivers/mtd/nand/r852.c
+++ b/drivers/mtd/nand/r852.c
@@ -245,7 +245,7 @@ static void r852_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
}
/* write DWORD chinks - faster */
- while (len) {
+ while (len >= 4) {
reg = buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24;
r852_write_reg_dword(dev, R852_DATALINE, reg);
buf += 4;
@@ -254,8 +254,10 @@ static void r852_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
}
/* write rest */
- while (len)
+ while (len > 0) {
r852_write_reg(dev, R852_DATALINE, *buf++);
+ len--;
+ }
}
/*
--
1.7.9.5
next prev parent reply other threads:[~2014-05-21 6:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-21 6:16 [PATCH 0/6] mtd: small cleanups Brian Norris
2014-05-21 6:16 ` [PATCH 1/6] mtd: pfow: remove unused variable Brian Norris
2014-05-21 6:16 ` [PATCH 2/6] mtd: slram: fix unused variable warning Brian Norris
2014-05-21 6:17 ` [PATCH 3/6] mtd: maps: sc520cdp: fix warnings Brian Norris
2014-05-21 6:17 ` [PATCH 4/6] mtd: nand_bbt: remove unused variable Brian Norris
2014-05-21 6:17 ` [PATCH 5/6] mtd: nand_bbt: handle error case for nand_create_badblock_pattern() Brian Norris
2014-05-21 6:17 ` Brian Norris [this message]
2014-05-28 7:07 ` [PATCH 0/6] mtd: small cleanups Brian Norris
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=1400653023-25757-7-git-send-email-computersforpeace@gmail.com \
--to=computersforpeace@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=maximlevitsky@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).