From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org
Cc: linux-mtd@lists.infradead.org,
Scott Branden <sbranden@broadcom.com>,
David Woodhouse <dwmw2@infradead.org>,
Akinobu Mita <akinobu.mita@gmail.com>,
Jiandong Zheng <jdzheng@broadcom.com>
Subject: [PATCH] mtd/nand: use string library
Date: Fri, 27 Jan 2012 23:24:49 +0900 [thread overview]
Message-ID: <1327674295-3700-2-git-send-email-akinobu.mita@gmail.com> (raw)
In-Reply-To: <1327674295-3700-1-git-send-email-akinobu.mita@gmail.com>
- Use memchr_inv to check if the data contains all 0xFF bytes.
It is faster than looping for each byte.
- Use memcmp to compare memory areas
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Jiandong Zheng <jdzheng@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
---
drivers/mtd/nand/davinci_nand.c | 7 +++----
drivers/mtd/nand/denali.c | 7 +++----
drivers/mtd/nand/diskonchip.c | 18 +++---------------
drivers/mtd/nand/nand_bbt.c | 16 +++++-----------
drivers/mtd/nand/nand_bcm_umi.c | 10 +++-------
5 files changed, 17 insertions(+), 41 deletions(-)
diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c
index 6e56615..423a7cc 100644
--- a/drivers/mtd/nand/davinci_nand.c
+++ b/drivers/mtd/nand/davinci_nand.c
@@ -315,10 +315,9 @@ static int nand_davinci_correct_4bit(struct mtd_info *mtd,
unsigned long timeo;
/* All bytes 0xff? It's an erased page; ignore its ECC. */
- for (i = 0; i < 10; i++) {
- if (ecc_code[i] != 0xff)
- goto compare;
- }
+ if (memchr_inv(ecc_code, 0xff, 10))
+ goto compare;
+
return 0;
compare:
diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 3984d48..a87e3a4 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -908,10 +908,9 @@ static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
*/
bool is_erased(uint8_t *buf, int len)
{
- int i = 0;
- for (i = 0; i < len; i++)
- if (buf[i] != 0xFF)
- return false;
+ if (memchr_inv(buf, 0xFF, len))
+ return false;
+
return true;
}
#define ECC_SECTOR_SIZE 512
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index df921e7..bf0602e 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -945,12 +945,8 @@ static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat, unsign
/* Note: this somewhat expensive test should not be triggered
often. It could be optimized away by examining the data in
the writebuf routine, and remembering the result. */
- for (i = 0; i < 512; i++) {
- if (dat[i] == 0xff)
- continue;
+ if (memchr_inv(dat, 0xff, 512))
emptymatch = 0;
- break;
- }
}
/* If emptymatch still =1, we do have an all-0xff data buffer.
Return all-0xff ecc value instead of the computed one, so
@@ -1000,24 +996,16 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat,
/* If emptymatch=1, the read syndrome is consistent with an
all-0xff data and stored ecc block. Check the stored ecc. */
if (emptymatch) {
- for (i = 0; i < 6; i++) {
- if (read_ecc[i] == 0xff)
- continue;
+ if (memchr_inv(read_ecc, 0xff, 6))
emptymatch = 0;
- break;
- }
}
/* If emptymatch still =1, check the data block. */
if (emptymatch) {
/* Note: this somewhat expensive test should not be triggered
often. It could be optimized away by examining the data in
the readbuf routine, and remembering the result. */
- for (i = 0; i < 512; i++) {
- if (dat[i] == 0xff)
- continue;
+ if (memchr_inv(dat, 0xff, 512))
emptymatch = 0;
- break;
- }
}
/* If emptymatch still =1, this is almost certainly a freshly-
erased block, in which case the ECC will not come out right.
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index 20a112f..a1b2dd5 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -100,10 +100,8 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc
end = paglen + td->offs;
if (td->options & NAND_BBT_SCANEMPTY) {
- for (i = 0; i < end; i++) {
- if (p[i] != 0xff)
- return -1;
- }
+ if (memchr_inv(p, 0xff, end))
+ return -1;
}
p += end;
@@ -133,14 +131,10 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc
*/
static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td)
{
- int i;
- uint8_t *p = buf;
-
/* Compare the pattern */
- for (i = 0; i < td->len; i++) {
- if (p[td->offs + i] != td->pattern[i])
- return -1;
- }
+ if (memcmp(buf + td->offs, td->pattern, td->len))
+ return -1;
+
return 0;
}
diff --git a/drivers/mtd/nand/nand_bcm_umi.c b/drivers/mtd/nand/nand_bcm_umi.c
index 46a6bc9..ad51dad 100644
--- a/drivers/mtd/nand/nand_bcm_umi.c
+++ b/drivers/mtd/nand/nand_bcm_umi.c
@@ -109,13 +109,9 @@ int nand_bcm_umi_bch_correct_page(uint8_t *datap, uint8_t *readEccData,
* see if errors are correctible
*/
if ((regValue & REG_UMI_BCH_CTRL_STATUS_UNCORR_ERR) > 0) {
- int i;
-
- for (i = 0; i < numEccBytes; i++) {
- if (readEccData[i] != 0xff) {
- /* errors cannot be fixed, return -1 */
- return -1;
- }
+ if (memchr_inv(readEccData, 0xff, numEccBytes)) {
+ /* errors cannot be fixed, return -1 */
+ return -1;
}
/* If ECC is unprogrammed then we can't correct,
* assume everything OK */
--
1.7.4.4
next parent reply other threads:[~2012-01-27 14:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1327674295-3700-1-git-send-email-akinobu.mita@gmail.com>
2012-01-27 14:24 ` Akinobu Mita [this message]
2012-01-27 17:16 ` [PATCH] mtd/nand: use string library Joe Perches
2012-01-27 18:52 ` Brian Norris
2012-01-27 23:52 ` Akinobu Mita
2012-01-31 17:57 ` Brian Norris
2012-02-01 13:11 ` Akinobu Mita
2012-01-27 14:24 ` [PATCH] mtd/onenand: " Akinobu Mita
2012-01-27 14:24 ` [PATCH] mtd/ubi: use memchr_inv Akinobu Mita
2012-01-27 14:24 ` [PATCH] mtd/inftlmount: " Akinobu Mita
2012-01-27 14:24 ` [PATCH] mtd/nftlmount: " Akinobu Mita
2012-01-27 14:24 ` [PATCH] mtd/tests: " Akinobu Mita
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=1327674295-3700-2-git-send-email-akinobu.mita@gmail.com \
--to=akinobu.mita@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=dwmw2@infradead.org \
--cc=jdzheng@broadcom.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=sbranden@broadcom.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