[PATCH] mtd/onenand: use string library

Akinobu Mita akinobu.mita at gmail.com
Fri Jan 27 09:24:50 EST 2012


- 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 at gmail.com>
Cc: David Woodhouse <dwmw2 at infradead.org>
Cc: Kyungmin Park <kyungmin.park at samsung.com>
Cc: linux-mtd at lists.infradead.org
---
 drivers/mtd/onenand/onenand_base.c |    8 ++------
 drivers/mtd/onenand/onenand_bbt.c  |   10 +++-------
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index a061bc1..374605f 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -3673,7 +3673,7 @@ static void flexonenand_get_size(struct mtd_info *mtd)
 static int flexonenand_check_blocks_erased(struct mtd_info *mtd, int start, int end)
 {
 	struct onenand_chip *this = mtd->priv;
-	int i, ret;
+	int ret;
 	int block;
 	struct mtd_oob_ops ops = {
 		.mode = MTD_OPS_PLACE_OOB,
@@ -3699,11 +3699,7 @@ static int flexonenand_check_blocks_erased(struct mtd_info *mtd, int start, int
 		if (ret)
 			return ret;
 
-		for (i = 0; i < mtd->oobsize; i++)
-			if (this->oob_buf[i] != 0xff)
-				break;
-
-		if (i != mtd->oobsize) {
+		if (memchr_inv(this->oob_buf, 0xff, mtd->oobsize)) {
 			printk(KERN_WARNING "%s: Block %d not erased.\n",
 				__func__, block);
 			return 1;
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
index 66fe3b7..8b1277b 100644
--- a/drivers/mtd/onenand/onenand_bbt.c
+++ b/drivers/mtd/onenand/onenand_bbt.c
@@ -32,14 +32,10 @@
  */
 static int check_short_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td)
 {
-	int i;
-	uint8_t *p = buf;
-
 	/* Compare the pattern */
-	for (i = 0; i < td->len; i++) {
-		if (p[i] != td->pattern[i])
-			return -1;
-	}
+	if (memcmp(buf, td->pattern, td->len))
+		return -1;
+
         return 0;
 }
 
-- 
1.7.4.4




More information about the linux-mtd mailing list