public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] nand_base: fix regression on nand with 64/128 oob size
@ 2017-03-12 20:02 Alexander Couzens
  2017-03-13  6:46 ` Boris Brezillon
  0 siblings, 1 reply; 15+ messages in thread
From: Alexander Couzens @ 2017-03-12 20:02 UTC (permalink / raw)
  To: linux-mtd; +Cc: Boris Brezillon, Richard Weinberger, Alexander Couzens

41b207a70d3a accidently changed the oob layout for nand when ECC doesn't use
the full available ecc reserved data.
This only affects controllers which use the default large page ops
nand_ooblayout_ecc_lp.

E.g. for davinci:
- nand has 2048 byte page, 64 byte oob
- 3 byte ecc every 512 byte using 1bit hw ecc
- requires 12 byte of oob space for ecc
- old layout reserved 24 byte based on 64 byte oob

Old layout started using byte from offset 40 while new layout
uses the last X bytes so it fits into the end of oob.
Meaning in this example the old layout uses byte 40-51, while
the new layout use byte 52-63.

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
---
 drivers/mtd/nand/nand_base.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index b0524f8accb6..ba88345fd334 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -112,8 +112,25 @@ static int nand_ooblayout_ecc_lp(struct mtd_info *mtd, int section,
 	if (section)
 		return -ERANGE;
 
+	/* to be compatible with previous layouts
+	 * 64 byte oob must have ecc data at byte 40,
+	 * 128 byte oob must have ecc data at byte 80 */
+	switch (mtd->oobsize) {
+	case 64:
+		oobregion->offset = 40;
+		break;
+	case 128:
+		oobregion->offset = 80;
+		break;
+	default:
+		oobregion->offset = mtd->oobsize - oobregion->length;
+		break;
+	}
+
 	oobregion->length = ecc->total;
-	oobregion->offset = mtd->oobsize - oobregion->length;
+	if (oobregion->offset + oobregion->length > mtd->oobsize) {
+		return -ERANGE;
+	}
 
 	return 0;
 }
-- 
2.12.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2017-05-03  1:57 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-12 20:02 [PATCH] nand_base: fix regression on nand with 64/128 oob size Alexander Couzens
2017-03-13  6:46 ` Boris Brezillon
2017-05-02  8:13   ` [PATCH 0/3][v2] fixing 1bit hamming Alexander Couzens
2017-05-02  8:21     ` Boris Brezillon
2017-05-02 10:19     ` [PATCH][v3] mtd: nand: add ooblayout for old hamming layout Alexander Couzens
2017-05-02 12:03       ` Boris Brezillon
2017-05-03  1:57         ` Brian Norris
2017-05-02  8:13   ` [PATCH 1/3][v2] mtd/nand: " Alexander Couzens
2017-05-02  8:41     ` Boris Brezillon
2017-05-02  8:57     ` Boris Brezillon
2017-05-02  8:13   ` [PATCH 2/3][v2] nand_base: use nand_ooblayout_lp_hamming_ops for 1bit hamming as default Alexander Couzens
2017-05-02  8:49     ` Boris Brezillon
2017-05-02  8:13   ` [PATCH 3/3][v3] mtd: nand: davinci: set ECC algorithm explicitly for HW based ECC Alexander Couzens
2017-05-02  9:00     ` Boris Brezillon
2017-05-02 10:30       ` Boris Brezillon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox