mtd: nand: use ECC, if present, when scanning OOB

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Sat Sep 29 10:59:03 EDT 2012


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=a7e68834fc273930c17e3decaddc13acb87a7dce
Commit:     a7e68834fc273930c17e3decaddc13acb87a7dce
Parent:     491ed06f334955578f0c43d298c46ea1a7ea9e1b
Author:     Brian Norris <computersforpeace at gmail.com>
AuthorDate: Fri Jun 22 16:35:45 2012 -0700
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Sat Sep 29 14:51:55 2012 +0100

    mtd: nand: use ECC, if present, when scanning OOB
    
    scan_read_raw_oob() is used in only in places where the MTD_OPS_PLACE_OOB mode
    is preferable to MTD_OPS_RAW mode, so use MTD_OPS_PLACE_OOB instead.
    MTD_OPS_PLACE_OOB provides the same functionality with the potential[1] added
    bonus of error correction.
    
    This brings scan_block_full() in line with scan_block_fast() so that they
    both read bad block markers with MTD_OPS_PLACE_OOB. This can help in
    preventing 0xff markers (in good blocks) from being interpreted as bad
    block indicators in the presence of a single bitflip.
    
    Note that ECC error codes (EUCLEAN or EBADMSG) are already silently
    ignored in all users of scan_read_raw_oob().
    
    [1] Few  drivers perform proper error correction on OOB data. In those
        cases, the use of MTD_OPS_RAW vs. MTD_OPS_PLACE_OOB is not
        significant.
    
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
    Signed-off-by: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
    Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
 drivers/mtd/nand/nand_bbt.c |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index f5839f0..0e928f3 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -289,14 +289,24 @@ static int scan_read_raw_data(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
 	return mtd_read(mtd, offs, len, &retlen, buf);
 }
 
-/* Scan read raw data from flash */
+/**
+ * scan_read_raw_oob - [GENERIC] Scan data+OOB region to buffer
+ * @mtd: MTD device structure
+ * @buf: temporary buffer
+ * @offs: offset at which to scan
+ * @len: length of data region to read
+ *
+ * Scan read data from data+OOB. May traverse multiple pages, interleaving
+ * page,OOB,page,OOB,... in buf. Completes transfer and returns the "strongest"
+ * ECC condition (error or bitflip). May quit on the first (non-ECC) error.
+ */
 static int scan_read_raw_oob(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
 			 size_t len)
 {
 	struct mtd_oob_ops ops;
-	int res;
+	int res, ret = 0;
 
-	ops.mode = MTD_OPS_RAW;
+	ops.mode = MTD_OPS_PLACE_OOB;
 	ops.ooboffs = 0;
 	ops.ooblen = mtd->oobsize;
 
@@ -306,15 +316,18 @@ static int scan_read_raw_oob(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
 		ops.oobbuf = buf + ops.len;
 
 		res = mtd_read_oob(mtd, offs, &ops);
-
-		if (res)
-			return res;
+		if (res) {
+			if (!mtd_is_bitflip_or_eccerr(res))
+				return res;
+			else if (mtd_is_eccerr(res) || !ret)
+				ret = res;
+		}
 
 		buf += mtd->oobsize + mtd->writesize;
 		len -= mtd->writesize;
 		offs += mtd->writesize;
 	}
-	return 0;
+	return ret;
 }
 
 static int scan_read_raw(struct mtd_info *mtd, uint8_t *buf, loff_t offs,



More information about the linux-mtd-cvs mailing list