mtd: nand: Optimize checking of erased buffers
authorPavel Machek <pavel@ucw.cz>
Fri, 21 Apr 2017 10:51:07 +0000 (12:51 +0200)
committerBoris Brezillon <boris.brezillon@free-electrons.com>
Thu, 1 Jun 2017 08:09:24 +0000 (10:09 +0200)
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@denx.de>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
drivers/mtd/nand/nand_base.c

index ed08e3946727edfacf8d345b7e22a847e9bd6920..79d98c9fa8a7528e8ac815e33dd480151462bd3e 100644 (file)
@@ -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;