Skip to contentSkip to conversation

mtd: rawnand: fsmc: Fix Hamming ECC

PATCH In review Boris Brezillon 3 participants 4 messages Sep 4, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: rawnand: fsmc: Fix Hamming ECC

Apparently ECC bytes are not ordered as expected by nand_correct_data() in the ecc_calc buffer which leads to invalid bitflip correction when an ECC error is detected (can be reproduced with 'nandbiterrs -i').

Re-ordering ECC bytes seems to fix the problem.

While at it, get rid of the useless u8 cast.

Fixes 6c009ab89a21 ("mtd: generic FSMC NAND MTD driver")
---
 drivers/mtd/nand/raw/fsmc_nand.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mtd/nand/raw/fsmc_nand.c +3 -3
index f418236fa020..c79f8e965b38 100644
@@ -440,9 +440,9 @@ static int fsmc_read_hwecc_ecc1(struct mtd_info *mtd, const uint8_t *data,
 	uint32_t ecc_tmp;
 
 	ecc_tmp = readl_relaxed(host->regs_va + ECC1);
-	ecc[0] = (uint8_t) (ecc_tmp >> 0);
-	ecc[1] = (uint8_t) (ecc_tmp >> 8);
-	ecc[2] = (uint8_t) (ecc_tmp >> 16);
+	ecc[0] = ecc_tmp >> 8;
+	ecc[1] = ecc_tmp;
+	ecc[2] = ecc_tmp >> 16;
 
 	return 0;
 }
Signature · 1 line
2.14.1
maintainer Acked-by on v1 1/1
#1 lore raw

Hi Boris,

Boris Brezillon <[email protected]> wrote on Tue, 4 Sep 2018 11:14:38 +0200:

Quoted 6 lines

Apparently ECC bytes are not ordered as expected by nand_correct_data() in the ecc_calc buffer which leads to invalid bitflip correction when an ECC error is detected (can be reproduced with 'nandbiterrs -i').

Re-ordering ECC bytes seems to fix the problem.

Quoted 9 lines

While at it, get rid of the useless u8 cast.

Fixes 6c009ab89a21 ("mtd: generic FSMC NAND MTD driver")
---
 drivers/mtd/nand/raw/fsmc_nand.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Thanks,
Miquèl

Acked-by on v1 1/1
#2 lore raw
In reply to Boris Brezillon
Quoted 11 lines · Boris Brezillon

Apparently ECC bytes are not ordered as expected by nand_correct_data() in the ecc_calc buffer which leads to invalid bitflip correction when an ECC error is detected (can be reproduced with 'nandbiterrs -i').

Re-ordering ECC bytes seems to fix the problem.

While at it, get rid of the useless u8 cast.

Fixes 6c009ab89a21 ("mtd: generic FSMC NAND MTD driver")

Yours,
Linus Walleij

#3 lore raw
In reply to Boris Brezillon
Quoted 20 lines · On Tue, 4 Sep 2018 11:14:38 +0200 Boris Brezillon…

Apparently ECC bytes are not ordered as expected by nand_correct_data() in the ecc_calc buffer which leads to invalid bitflip correction when an ECC error is detected (can be reproduced with 'nandbiterrs -i').

Re-ordering ECC bytes seems to fix the problem.

While at it, get rid of the useless u8 cast.

Fixes 6c009ab89a21 ("mtd: generic FSMC NAND MTD driver")
---
 drivers/mtd/nand/raw/fsmc_nand.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mtd/nand/raw/fsmc_nand.c +0 -0
index f418236fa020..c79f8e965b38 100644

drivers/mtd/nand/raw/fsmc_nand.c static int fsmc_read_hwecc_ecc1(struct mtd_info *mtd, const uint8_t *data, · line 445

Quoted 9 lines
drivers/mtd/nand/raw/fsmc_nand.c +3 -3
@@ -440,9 +440,9 @@ static int fsmc_read_hwecc_ecc1(struct mtd_info *mtd, const uint8_t *data,
 	uint32_t ecc_tmp;
 
 	ecc_tmp = readl_relaxed(host->regs_va + ECC1);
-	ecc[0] = (uint8_t) (ecc_tmp >> 0);
-	ecc[1] = (uint8_t) (ecc_tmp >> 8);
-	ecc[2] = (uint8_t) (ecc_tmp >> 16);
+	ecc[0] = ecc_tmp >> 8;
+	ecc[1] = ecc_tmp;
+	ecc[2] = ecc_tmp >> 16;

Hm, looks like there's a Kconfig option (CONFIG_MTD_NAND_ECC_SMC) to let nand_ecc_correct() swap those 2 bytes for us, but it's clearly not a good thing to take this decision based on a Kconfig option (does not work if you want the same kernel to be used on various platforms).

I'll come up with a better solution.