Patchwork [v2,6/7] mtd: nand: add sanity check of ecc strength to nand_scan_tail()

login
register
mail settings
Submitter Mike Dunn
Date April 25, 2012, 7:06 p.m.
Message ID <1335380771-27805-7-git-send-email-mikedunn@newsguy.com>
Download mbox | patch
Permalink /patch/155064/
State Accepted
Commit e2788c98b98269a3131bffd2b57599280d7abd73
Headers show

Comments

Mike Dunn - April 25, 2012, 7:06 p.m.
This patch adds sanity checks that ensure that drivers for controllers with
hardware ECC set the 'strength' element in struct nand_ecc_ctrl.  Also stylistic
changes to the line that calculates strength for software ECC.

This v2 simplifies the check.  Thanks Brian! [1]

[1] http://lists.infradead.org/pipermail/linux-mtd/2012-April/040890.html

Signed-off-by: Mike Dunn <mikedunn@newsguy.com>
---
 drivers/mtd/nand/nand_base.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
Brian Norris - May 2, 2012, 6:17 a.m.
On Wed, Apr 25, 2012 at 12:06 PM, Mike Dunn <mikedunn@newsguy.com> wrote:
> This patch adds sanity checks that ensure that drivers for controllers with
> hardware ECC set the 'strength' element in struct nand_ecc_ctrl.  Also stylistic
> changes to the line that calculates strength for software ECC.
>
> This v2 simplifies the check.  Thanks Brian! [1]

Thank you for going through the review process! This series provides a
good general fix for something that's been kind of masked in hardware
like mine (which has its own threshold for suppressing bitflip
messages).

> [1] http://lists.infradead.org/pipermail/linux-mtd/2012-April/040890.html
>
> Signed-off-by: Mike Dunn <mikedunn@newsguy.com>

If we're looking for Ack's to rebase with:

Acked-by: Brian Norris <computersforpeace@gmail.com>

Patch

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 3137abd..dac0afa 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3345,8 +3345,13 @@  int nand_scan_tail(struct mtd_info *mtd)
 		if (!chip->ecc.write_oob)
 			chip->ecc.write_oob = nand_write_oob_syndrome;
 
-		if (mtd->writesize >= chip->ecc.size)
+		if (mtd->writesize >= chip->ecc.size) {
+			if (!chip->ecc.strength) {
+				pr_warn("Driver must set ecc.strength when using hardware ECC\n");
+				BUG();
+			}
 			break;
+		}
 		pr_warn("%d byte HW ECC not possible on "
 			   "%d byte page size, fallback to SW ECC\n",
 			   chip->ecc.size, mtd->writesize);
@@ -3401,7 +3406,7 @@  int nand_scan_tail(struct mtd_info *mtd)
 			BUG();
 		}
 		chip->ecc.strength =
-			chip->ecc.bytes*8 / fls(8*chip->ecc.size);
+			chip->ecc.bytes * 8 / fls(8 * chip->ecc.size);
 		break;
 
 	case NAND_ECC_NONE: