mtd: nand: mxc: Fix mxc_v1 ooblayout
PATCH 1/1 mtd: nand: mxc: Fix mxc_v1 ooblayout
Commit a894cf6c5a82 ("mtd: nand: mxc: switch to mtd_ooblayout_ops") introduced a bug in the OOB layout description. Even if the driver claims that 3 ECC bytes are reserved to protect 512 bytes of data, it's actually 5 ECC bytes to protect 512+6 bytes of data (some OOB bytes are also protected using extra ECC bytes).
Fix the mxc_v1_ooblayout_{free,ecc}() functions to reflect this behavior.
--- drivers/mtd/nand/mxc_nand.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/mtd/nand/mxc_nand.c +2 -3
@@ -886,7 +886,7 @@ static int mxc_v1_ooblayout_ecc(struct mtd_info *mtd, int section,return -ERANGE ; oobregion->offset = (section *16 ) +6 ; - oobregion->length = nand_chip->ecc.bytes; + oobregion->length =5 ;return 0 ; }
@@ -908,8 +908,7 @@ static int mxc_v1_ooblayout_free(struct mtd_info *mtd, int section, oobregion->length =4 ; } }else { - oobregion->offset = ((section -1 ) *16 ) + - nand_chip->ecc.bytes +6 ; + oobregion->offset = ((section -1 ) *16 ) +5 +6 ;if (section < nand_chip->ecc.steps) oobregion->length = (section *16 ) +6 - oobregion->offset;
Signature · 1 line
2.7.4
PATCH 1/1 mtd: nand: mxc: Fix mxc_v1 ooblayout
Quoted 20 lines · Boris Brezillon
Commit
a894cf6c5a82("mtd: nand: mxc: switch tomtd_ooblayout_ops") introduced a bug in the OOB layout description. Even if the driver claims that 3 ECC bytes are reserved to protect 512 bytes of data, it's actually 5 ECC bytes to protect 512+6 bytes of data (some OOB bytes are also protected using extra ECC bytes).Fix the mxc_v1_ooblayout_{free,ecc}() functions to reflect this behavior.
Signed-off-by Boris Brezillon <[email protected]>Fixes a894cf6c5a82 ("mtd: nand: mxc: switch to mtd_ooblayout_ops")Cc <[email protected]>--- drivers/mtd/nand/mxc_nand.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/mtd/nand/mxc_nand.c +0
-0
drivers/mtd/nand/mxc_nand.c static int mxc_v1_ooblayout_ecc(struct mtd_info *mtd, int section, · line 889
Quoted 5 lines
drivers/mtd/nand/mxc_nand.c +1
-1@@ -886,7 +886,7 @@ static int mxc_v1_ooblayout_ecc(struct mtd_info *mtd, int section,return -ERANGE ; oobregion->offset = (section *16 ) +6 ; - oobregion->length = nand_chip->ecc.bytes; + oobregion->length =5 ;
Use a macro instead of hard-coding a value please :)
drivers/mtd/nand/mxc_nand.c static int mxc_v1_ooblayout_free(struct mtd_info *mtd, int section, · line 911
Quoted 9 lines
drivers/mtd/nand/mxc_nand.c +1
-2return 0 ; }@@ -908,8 +908,7 @@ static int mxc_v1_ooblayout_free(struct mtd_info *mtd, int section, oobregion->length =4 ; } }else { - oobregion->offset = ((section -1 ) *16 ) + - nand_chip->ecc.bytes +6 ; + oobregion->offset = ((section -1 ) *16 ) +5 +6 ;
DTTO here, the math here is cryptic enough.
Quoted 4 lines
drivers/mtd/nand/mxc_nand.c +0
-0if (section < nand_chip->ecc.steps) oobregion->length = (section *16 ) +6 - oobregion->offset;
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 mtd: nand: mxc: Fix mxc_v1 ooblayout
Quoted 23 lines · On Fri, 25 Nov 2016 10:58:26 +0100 Marek Vasut <[email protected]> wrote:
Quoted 22 lines · Boris Brezillon
Commit
a894cf6c5a82("mtd: nand: mxc: switch tomtd_ooblayout_ops") introduced a bug in the OOB layout description. Even if the driver claims that 3 ECC bytes are reserved to protect 512 bytes of data, it's actually 5 ECC bytes to protect 512+6 bytes of data (some OOB bytes are also protected using extra ECC bytes).Fix the mxc_v1_ooblayout_{free,ecc}() functions to reflect this behavior.
Signed-off-by Boris Brezillon <[email protected]>Fixes a894cf6c5a82 ("mtd: nand: mxc: switch to mtd_ooblayout_ops")Cc <[email protected]>--- drivers/mtd/nand/mxc_nand.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/mtd/nand/mxc_nand.c +0
-0@@ -886,7 +886,7 @@ static int mxc_v1_ooblayout_ecc(struct mtd_info *mtd, int section,return -ERANGE ;
Quoted 5 lines
drivers/mtd/nand/mxc_nand.c static int mxc_v1_ooblayout_ecc(struct mtd_info *mtd, int section, · line 889
Quoted 3 lines
drivers/mtd/nand/mxc_nand.c +1
-1oobregion->offset = (section *16 ) +6 ; - oobregion->length = nand_chip->ecc.bytes; + oobregion->length =5 ;Use a macro instead of hard-coding a value please :)
Ideally, we should change ->eccbytes value in the imx27_nand_devtype_data and imx21_nand_devtype_data definitions, but I fear it could break other things.
I'll define a macro.
Quoted 19 lines
drivers/mtd/nand/mxc_nand.c static int mxc_v1_ooblayout_free(struct mtd_info *mtd, int section, · line 911
Quoted 10 lines
drivers/mtd/nand/mxc_nand.c +1
-2return 0 ; }@@ -908,8 +908,7 @@ static int mxc_v1_ooblayout_free(struct mtd_info *mtd, int section, oobregion->length =4 ; } }else { - oobregion->offset = ((section -1 ) *16 ) + - nand_chip->ecc.bytes +6 ; + oobregion->offset = ((section -1 ) *16 ) +5 +6 ;DTTO here, the math here is cryptic enough.
Quoted 4 lines
drivers/mtd/nand/mxc_nand.c +0
-0if (section < nand_chip->ecc.steps) oobregion->length = (section *16 ) +6 - oobregion->offset;
PATCH 1/1 mtd: nand: mxc: Fix mxc_v1 ooblayout
Quoted 32 lines · Boris Brezillon
Quoted 23 lines · On Fri, 25 Nov 2016 10:58:26 +0100 Marek Vasut <[email protected]> wrote:
Quoted 22 lines · Boris Brezillon
Commit
a894cf6c5a82("mtd: nand: mxc: switch tomtd_ooblayout_ops") introduced a bug in the OOB layout description. Even if the driver claims that 3 ECC bytes are reserved to protect 512 bytes of data, it's actually 5 ECC bytes to protect 512+6 bytes of data (some OOB bytes are also protected using extra ECC bytes).Fix the mxc_v1_ooblayout_{free,ecc}() functions to reflect this behavior.
Signed-off-by Boris Brezillon <[email protected]>Fixes a894cf6c5a82 ("mtd: nand: mxc: switch to mtd_ooblayout_ops")Cc <[email protected]>--- drivers/mtd/nand/mxc_nand.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/mtd/nand/mxc_nand.c +0
-0@@ -886,7 +886,7 @@ static int mxc_v1_ooblayout_ecc(struct mtd_info *mtd, int section,return -ERANGE ;Quoted 5 lines
drivers/mtd/nand/mxc_nand.c static int mxc_v1_ooblayout_ecc(struct mtd_info *mtd, int section, · line 889
Quoted 3 lines
drivers/mtd/nand/mxc_nand.c +1
-1oobregion->offset = (section *16 ) +6 ; - oobregion->length = nand_chip->ecc.bytes; + oobregion->length =5 ;Use a macro instead of hard-coding a value please :)
Quoted 3 lines
Ideally, we should change ->eccbytes value in the
imx27_nand_devtype_dataandimx21_nand_devtype_datadefinitions, but I fear it could break other things.
I was wondering about that too :) Break what things ?
Quoted 1 line
I'll define a macro.
Thanks!
Quoted 20 lines
Quoted 19 lines
drivers/mtd/nand/mxc_nand.c static int mxc_v1_ooblayout_free(struct mtd_info *mtd, int section, · line 911
Quoted 10 lines
drivers/mtd/nand/mxc_nand.c +1
-2return 0 ; }@@ -908,8 +908,7 @@ static int mxc_v1_ooblayout_free(struct mtd_info *mtd, int section, oobregion->length =4 ; } }else { - oobregion->offset = ((section -1 ) *16 ) + - nand_chip->ecc.bytes +6 ; + oobregion->offset = ((section -1 ) *16 ) +5 +6 ;DTTO here, the math here is cryptic enough.
Quoted 4 lines
drivers/mtd/nand/mxc_nand.c +0
-0if (section < nand_chip->ecc.steps) oobregion->length = (section *16 ) +6 - oobregion->offset;
Signature · 2 lines
Best regards, Marek Vasut