Skip to contentSkip to conversation

mtd: rawnand: sunxi: fix ECC count register indexing

PATCH In review James Hilliard 2 participants 2 messages Jul 14 – Jul 15

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

PATCH 1/1 mtd: rawnand: sunxi: fix ECC count register indexing

Each ECC error-count register contains four 8-bit correction counts. The register-offset helper already selects the register using the ECC block index divided by four, but field extraction shifts by the full block index. This produces shifts of 32 bits or more for each register after the first.

Use the block index modulo four when extracting the correction count.

Fixes 4ccae81cdadc ("mtd: nand: Add the sunxi NAND controller driver")
---
 drivers/mtd/nand/raw/sunxi_nand.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/sunxi_nand.h +1 -1
index 1b2c514852d..96b65c52685 100644
@@ -167,7 +167,7 @@
 #define NFC_ECC_PAT_FOUND(x)	BIT(x)
 #define NFC_ECC_PAT_FOUND_MSK(nfc) ((nfc)->caps->pat_found_mask)
 
-#define NFC_ECC_ERR_CNT(b, x)	(((x) >> ((b) * 8)) & 0xff)
+#define NFC_ECC_ERR_CNT(b, x)	(((x) >> (((b) % 4) * 8)) & 0xff)
 
 #define NFC_USER_DATA_LEN_MSK(step) \
 	(0xf << (((step) % NFC_REG_USER_DATA_LEN_CAPACITY) * 4))
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw

Le 15/07/2026 à 01:32, James Hilliard a écrit :

Quoted 10 lines

Each ECC error-count register contains four 8-bit correction counts. The register-offset helper already selects the register using the ECC block index divided by four, but field extraction shifts by the full block index. This produces shifts of 32 bits or more for each register after the first.

Use the block index modulo four when extracting the correction count.

Fixes 4ccae81cdadc ("mtd: nand: Add the sunxi NAND controller driver")

NB: While the fix is valid, it doesn't change anything at the end since the step is always 0 here. But it's better to have the right formula anyway.

Quoted 9 lines
---
  drivers/mtd/nand/raw/sunxi_nand.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/sunxi_nand.h +0 -0
index 1b2c514852d..96b65c52685 100644

drivers/mtd/nand/raw/sunxi_nand.h line 173

Quoted 8 lines
drivers/mtd/nand/raw/sunxi_nand.h +1 -1
@@ -167,7 +167,7 @@
  #define NFC_ECC_PAT_FOUND(x)	BIT(x)
  #define NFC_ECC_PAT_FOUND_MSK(nfc) ((nfc)->caps->pat_found_mask)
 
-#define NFC_ECC_ERR_CNT(b, x)	(((x) >> ((b) * 8)) & 0xff)
+#define NFC_ECC_ERR_CNT(b, x)	(((x) >> (((b) % 4) * 8)) & 0xff)
 
  #define NFC_USER_DATA_LEN_MSK(step) \
  	(0xf << (((step) % NFC_REG_USER_DATA_LEN_CAPACITY) * 4))

regards,
Richard