Patchwork mtd/tests: use memchr_inv

login
register
mail settings
Submitter Akinobu Mita
Date Jan. 27, 2012, 2:24 p.m.
Message ID <1327674295-3700-7-git-send-email-akinobu.mita@gmail.com>
Download mbox | patch
Permalink /patch/138233/
State New
Headers show

Comments

Akinobu Mita - Jan. 27, 2012, 2:24 p.m.
Use memchr_inv to check if the data contains all 0xFF bytes.  It is
faster than looping for each byte.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
---
 drivers/mtd/tests/mtd_pagetest.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

Patch

diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c
index 252ddb0..08847cf 100644
--- a/drivers/mtd/tests/mtd_pagetest.c
+++ b/drivers/mtd/tests/mtd_pagetest.c
@@ -401,6 +401,7 @@  static int erasetest(void)
 	size_t read, written;
 	int err = 0, i, ebnum, ok = 1;
 	loff_t addr0;
+	unsigned char *p;
 
 	printk(PRINT_PREF "erasetest\n");
 
@@ -442,14 +443,13 @@  static int erasetest(void)
 
 	printk(PRINT_PREF "verifying 1st page of block %d is all 0xff\n",
 	       ebnum);
-	for (i = 0; i < pgsize; ++i)
-		if (twopages[i] != 0xff) {
-			printk(PRINT_PREF "verifying all 0xff failed at %d\n",
-			       i);
-			errcnt += 1;
-			ok = 0;
-			break;
-		}
+	p = memchr_inv(twopages, 0xff, pgsize);
+	if (p) {
+		printk(PRINT_PREF "verifying all 0xff failed at %d\n",
+			       p - twopages);
+		errcnt += 1;
+		ok = 0;
+	}
 
 	if (ok && !err)
 		printk(PRINT_PREF "erasetest ok\n");