* [PATCH] mtd: nand: mxc: Fix mxc_v1 ooblayout
@ 2016-11-25 9:13 Boris Brezillon
2016-11-25 9:58 ` Marek Vasut
0 siblings, 1 reply; 4+ messages in thread
From: Boris Brezillon @ 2016-11-25 9:13 UTC (permalink / raw)
To: linux-arm-kernel
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.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Fixes: a894cf6c5a82 ("mtd: nand: mxc: switch to mtd_ooblayout_ops")
Cc: <stable@vger.kernel.org>
---
drivers/mtd/nand/mxc_nand.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index 61ca020c5272..c19ec4f0983e 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -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;
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] mtd: nand: mxc: Fix mxc_v1 ooblayout
2016-11-25 9:13 [PATCH] mtd: nand: mxc: Fix mxc_v1 ooblayout Boris Brezillon
@ 2016-11-25 9:58 ` Marek Vasut
2016-11-25 10:27 ` Boris Brezillon
0 siblings, 1 reply; 4+ messages in thread
From: Marek Vasut @ 2016-11-25 9:58 UTC (permalink / raw)
To: linux-arm-kernel
On 11/25/2016 10:13 AM, Boris Brezillon wrote:
> 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.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> Fixes: a894cf6c5a82 ("mtd: nand: mxc: switch to mtd_ooblayout_ops")
> Cc: <stable@vger.kernel.org>
> ---
> drivers/mtd/nand/mxc_nand.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
> index 61ca020c5272..c19ec4f0983e 100644
> --- a/drivers/mtd/nand/mxc_nand.c
> +++ b/drivers/mtd/nand/mxc_nand.c
> @@ -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 :)
> 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;
DTTO here, the math here is cryptic enough.
> if (section < nand_chip->ecc.steps)
> oobregion->length = (section * 16) + 6 -
> oobregion->offset;
>
--
Best regards,
Marek Vasut
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] mtd: nand: mxc: Fix mxc_v1 ooblayout
2016-11-25 9:58 ` Marek Vasut
@ 2016-11-25 10:27 ` Boris Brezillon
2016-11-25 10:40 ` Marek Vasut
0 siblings, 1 reply; 4+ messages in thread
From: Boris Brezillon @ 2016-11-25 10:27 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, 25 Nov 2016 10:58:26 +0100
Marek Vasut <marek.vasut@gmail.com> wrote:
> On 11/25/2016 10:13 AM, Boris Brezillon wrote:
> > 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.
> >
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> > Fixes: a894cf6c5a82 ("mtd: nand: mxc: switch to mtd_ooblayout_ops")
> > Cc: <stable@vger.kernel.org>
> > ---
> > drivers/mtd/nand/mxc_nand.c | 5 ++---
> > 1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
> > index 61ca020c5272..c19ec4f0983e 100644
> > --- a/drivers/mtd/nand/mxc_nand.c
> > +++ b/drivers/mtd/nand/mxc_nand.c
> > @@ -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 :)
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.
>
> > 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;
>
> DTTO here, the math here is cryptic enough.
>
> > if (section < nand_chip->ecc.steps)
> > oobregion->length = (section * 16) + 6 -
> > oobregion->offset;
> >
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] mtd: nand: mxc: Fix mxc_v1 ooblayout
2016-11-25 10:27 ` Boris Brezillon
@ 2016-11-25 10:40 ` Marek Vasut
0 siblings, 0 replies; 4+ messages in thread
From: Marek Vasut @ 2016-11-25 10:40 UTC (permalink / raw)
To: linux-arm-kernel
On 11/25/2016 11:27 AM, Boris Brezillon wrote:
> On Fri, 25 Nov 2016 10:58:26 +0100
> Marek Vasut <marek.vasut@gmail.com> wrote:
>
>> On 11/25/2016 10:13 AM, Boris Brezillon wrote:
>>> 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.
>>>
>>> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
>>> Fixes: a894cf6c5a82 ("mtd: nand: mxc: switch to mtd_ooblayout_ops")
>>> Cc: <stable@vger.kernel.org>
>>> ---
>>> drivers/mtd/nand/mxc_nand.c | 5 ++---
>>> 1 file changed, 2 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
>>> index 61ca020c5272..c19ec4f0983e 100644
>>> --- a/drivers/mtd/nand/mxc_nand.c
>>> +++ b/drivers/mtd/nand/mxc_nand.c
>>> @@ -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 :)
>
> 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 was wondering about that too :) Break what things ?
> I'll define a macro.
Thanks!
>>
>>> 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;
>>
>> DTTO here, the math here is cryptic enough.
>>
>>> if (section < nand_chip->ecc.steps)
>>> oobregion->length = (section * 16) + 6 -
>>> oobregion->offset;
>>>
>>
>>
>
--
Best regards,
Marek Vasut
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-11-25 10:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-25 9:13 [PATCH] mtd: nand: mxc: Fix mxc_v1 ooblayout Boris Brezillon
2016-11-25 9:58 ` Marek Vasut
2016-11-25 10:27 ` Boris Brezillon
2016-11-25 10:40 ` Marek Vasut
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).