mtd: nand: Optimize checking of erased buffers

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Thu Jul 13 10:59:13 PDT 2017


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=086567f12e1188c57e061a53825a5eff5a7923a0
Commit:     086567f12e1188c57e061a53825a5eff5a7923a0
Parent:     838ff7b333263abc9e7e026bb225ed66511f450f
Author:     Pavel Machek <pavel at ucw.cz>
AuthorDate: Fri Apr 21 12:51:07 2017 +0200
Committer:  Boris Brezillon <boris.brezillon at free-electrons.com>
CommitDate: Thu Jun 1 10:09:24 2017 +0200

    mtd: nand: Optimize checking of erased buffers
    
    If we see ~0UL in flash, there's no need for hweight, and no need to
    check number of bitflips. So this should be net win.
    
    Signed-off-by: Pavel Machek <pavel at denx.de>
    Signed-off-by: Boris Brezillon <boris.brezillon at free-electrons.com>
---
 drivers/mtd/nand/nand_base.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index ed08e39..79d98c9 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1421,7 +1421,10 @@ static int nand_check_erased_buf(void *buf, int len, int bitflips_threshold)
 
 	for (; len >= sizeof(long);
 	     len -= sizeof(long), bitmap += sizeof(long)) {
-		weight = hweight_long(*((unsigned long *)bitmap));
+		unsigned long d = *((unsigned long *)bitmap);
+		if (d == ~0UL)
+			continue;
+		weight = hweight_long(d);
 		bitflips += BITS_PER_LONG - weight;
 		if (unlikely(bitflips > bitflips_threshold))
 			return -EBADMSG;



More information about the linux-mtd-cvs mailing list