* [PATCH 1/3] mtd: rawnand: Fix wrongful fallthrough NAND_ECC_SOFT
2020-09-17 7:52 [PATCH 0/3] mtd: rawnand: Fix HW ECC handling Tudor Ambarus
@ 2020-09-17 7:52 ` Tudor Ambarus
2020-09-28 15:00 ` Miquel Raynal
2020-09-17 7:52 ` [PATCH 2/3] mtd: rawnand: Introduce nand_set_ecc_on_host_ops() Tudor Ambarus
2020-09-17 7:52 ` [PATCH 3/3] mtd: rawnand: Don't overwrite the error code from nand_set_ecc_soft_ops() Tudor Ambarus
2 siblings, 1 reply; 7+ messages in thread
From: Tudor Ambarus @ 2020-09-17 7:52 UTC (permalink / raw)
To: miquel.raynal, richard, vigneshr, boris.brezillon
Cc: linux-mtd, linux-kernel, Tudor Ambarus, Santiago Esteban
In case of valid HW ECC, where the fallback to SW ECC is not needed,
the mentioned commit breaks the "switch (ecc->placement)" statement,
but then wrongly falls through the "case NAND_ECC_SOFT" of the
parent "switch (ecc->mode)". This causes an -EINVAL in
nand_set_ecc_soft_ops(), because for the valid HW ECC cases
ecc->mode is set to NAND_ECC_HW, but the nand_set_ecc_soft_ops()
expects a NAND_ECC_SOFT mode, thus -EINVAL.
Move the fallback to SW ECC after the setting of the ECC on host ops.
With this, when a valid HW ECC is available, we break the
"switch (ecc->mode)" statement, and when a fallback to SW ECC is
needed, we fallthrough "case NAND_ECC_SOFT".
Fixes: d3f8ec8e979b ("mtd: rawnand: Separate the ECC engine type and the ECC byte placement")
Reported-by: Santiago Esteban <santiago.esteban@microchip.com>
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
drivers/mtd/nand/raw/nand_base.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index d42832bedff5..bd30f6632fe2 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -5665,19 +5665,6 @@ static int nand_scan_tail(struct nand_chip *chip)
ecc->read_oob = nand_read_oob_syndrome;
if (!ecc->write_oob)
ecc->write_oob = nand_write_oob_syndrome;
-
- if (mtd->writesize >= ecc->size) {
- if (!ecc->strength) {
- WARN(1, "Driver must set ecc.strength when using hardware ECC\n");
- ret = -EINVAL;
- goto err_nand_manuf_cleanup;
- }
- break;
- }
- pr_warn("%d byte HW ECC not possible on %d byte page size, fallback to SW ECC\n",
- ecc->size, mtd->writesize);
- ecc->engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
- ecc->algo = NAND_ECC_ALGO_HAMMING;
break;
default:
@@ -5686,6 +5673,19 @@ static int nand_scan_tail(struct nand_chip *chip)
ret = -EINVAL;
goto err_nand_manuf_cleanup;
}
+
+ if (mtd->writesize >= ecc->size) {
+ if (!ecc->strength) {
+ WARN(1, "Driver must set ecc.strength when using hardware ECC\n");
+ ret = -EINVAL;
+ goto err_nand_manuf_cleanup;
+ }
+ break;
+ }
+ pr_warn("%d byte HW ECC not possible on %d byte page size, fallback to SW ECC\n",
+ ecc->size, mtd->writesize);
+ ecc->engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
+ ecc->algo = NAND_ECC_ALGO_HAMMING;
fallthrough;
case NAND_ECC_ENGINE_TYPE_SOFT:
--
2.25.1
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 1/3] mtd: rawnand: Fix wrongful fallthrough NAND_ECC_SOFT
2020-09-17 7:52 ` [PATCH 1/3] mtd: rawnand: Fix wrongful fallthrough NAND_ECC_SOFT Tudor Ambarus
@ 2020-09-28 15:00 ` Miquel Raynal
0 siblings, 0 replies; 7+ messages in thread
From: Miquel Raynal @ 2020-09-28 15:00 UTC (permalink / raw)
To: Tudor Ambarus, miquel.raynal, richard, vigneshr, boris.brezillon
Cc: linux-mtd, linux-kernel, Santiago Esteban
On Thu, 2020-09-17 at 07:52:11 UTC, Tudor Ambarus wrote:
> In case of valid HW ECC, where the fallback to SW ECC is not needed,
> the mentioned commit breaks the "switch (ecc->placement)" statement,
> but then wrongly falls through the "case NAND_ECC_SOFT" of the
> parent "switch (ecc->mode)". This causes an -EINVAL in
> nand_set_ecc_soft_ops(), because for the valid HW ECC cases
> ecc->mode is set to NAND_ECC_HW, but the nand_set_ecc_soft_ops()
> expects a NAND_ECC_SOFT mode, thus -EINVAL.
>
> Move the fallback to SW ECC after the setting of the ECC on host ops.
> With this, when a valid HW ECC is available, we break the
> "switch (ecc->mode)" statement, and when a fallback to SW ECC is
> needed, we fallthrough "case NAND_ECC_SOFT".
>
> Fixes: d3f8ec8e979b ("mtd: rawnand: Separate the ECC engine type and the ECC byte placement")
> Reported-by: Santiago Esteban <santiago.esteban@microchip.com>
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/3] mtd: rawnand: Introduce nand_set_ecc_on_host_ops()
2020-09-17 7:52 [PATCH 0/3] mtd: rawnand: Fix HW ECC handling Tudor Ambarus
2020-09-17 7:52 ` [PATCH 1/3] mtd: rawnand: Fix wrongful fallthrough NAND_ECC_SOFT Tudor Ambarus
@ 2020-09-17 7:52 ` Tudor Ambarus
2020-09-28 15:00 ` Miquel Raynal
2020-09-17 7:52 ` [PATCH 3/3] mtd: rawnand: Don't overwrite the error code from nand_set_ecc_soft_ops() Tudor Ambarus
2 siblings, 1 reply; 7+ messages in thread
From: Tudor Ambarus @ 2020-09-17 7:52 UTC (permalink / raw)
To: miquel.raynal, richard, vigneshr, boris.brezillon
Cc: linux-mtd, linux-kernel, Tudor Ambarus
There were too many levels of indentation and the code was
hard to read. Introduce a new function, similar to
nand_set_ecc_soft_ops().
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
drivers/mtd/nand/raw/nand_base.c | 114 +++++++++++++++++--------------
1 file changed, 61 insertions(+), 53 deletions(-)
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index bd30f6632fe2..d3e0ca66382f 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -5139,6 +5139,65 @@ static void nand_scan_ident_cleanup(struct nand_chip *chip)
kfree(chip->parameters.onfi);
}
+static int nand_set_ecc_on_host_ops(struct nand_chip *chip)
+{
+ struct nand_ecc_ctrl *ecc = &chip->ecc;
+
+ switch (ecc->placement) {
+ case NAND_ECC_PLACEMENT_UNKNOWN:
+ case NAND_ECC_PLACEMENT_OOB:
+ /* Use standard hwecc read page function? */
+ if (!ecc->read_page)
+ ecc->read_page = nand_read_page_hwecc;
+ if (!ecc->write_page)
+ ecc->write_page = nand_write_page_hwecc;
+ if (!ecc->read_page_raw)
+ ecc->read_page_raw = nand_read_page_raw;
+ if (!ecc->write_page_raw)
+ ecc->write_page_raw = nand_write_page_raw;
+ if (!ecc->read_oob)
+ ecc->read_oob = nand_read_oob_std;
+ if (!ecc->write_oob)
+ ecc->write_oob = nand_write_oob_std;
+ if (!ecc->read_subpage)
+ ecc->read_subpage = nand_read_subpage;
+ if (!ecc->write_subpage && ecc->hwctl && ecc->calculate)
+ ecc->write_subpage = nand_write_subpage_hwecc;
+ fallthrough;
+
+ case NAND_ECC_PLACEMENT_INTERLEAVED:
+ if ((!ecc->calculate || !ecc->correct || !ecc->hwctl) &&
+ (!ecc->read_page ||
+ ecc->read_page == nand_read_page_hwecc ||
+ !ecc->write_page ||
+ ecc->write_page == nand_write_page_hwecc)) {
+ WARN(1, "No ECC functions supplied; hardware ECC not possible\n");
+ return -EINVAL;
+ }
+ /* Use standard syndrome read/write page function? */
+ if (!ecc->read_page)
+ ecc->read_page = nand_read_page_syndrome;
+ if (!ecc->write_page)
+ ecc->write_page = nand_write_page_syndrome;
+ if (!ecc->read_page_raw)
+ ecc->read_page_raw = nand_read_page_raw_syndrome;
+ if (!ecc->write_page_raw)
+ ecc->write_page_raw = nand_write_page_raw_syndrome;
+ if (!ecc->read_oob)
+ ecc->read_oob = nand_read_oob_syndrome;
+ if (!ecc->write_oob)
+ ecc->write_oob = nand_write_oob_syndrome;
+ break;
+
+ default:
+ pr_warn("Invalid NAND_ECC_PLACEMENT %d\n",
+ ecc->placement);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static int nand_set_ecc_soft_ops(struct nand_chip *chip)
{
struct mtd_info *mtd = nand_to_mtd(chip);
@@ -5619,60 +5678,9 @@ static int nand_scan_tail(struct nand_chip *chip)
switch (ecc->engine_type) {
case NAND_ECC_ENGINE_TYPE_ON_HOST:
-
- switch (ecc->placement) {
- case NAND_ECC_PLACEMENT_UNKNOWN:
- case NAND_ECC_PLACEMENT_OOB:
- /* Use standard hwecc read page function? */
- if (!ecc->read_page)
- ecc->read_page = nand_read_page_hwecc;
- if (!ecc->write_page)
- ecc->write_page = nand_write_page_hwecc;
- if (!ecc->read_page_raw)
- ecc->read_page_raw = nand_read_page_raw;
- if (!ecc->write_page_raw)
- ecc->write_page_raw = nand_write_page_raw;
- if (!ecc->read_oob)
- ecc->read_oob = nand_read_oob_std;
- if (!ecc->write_oob)
- ecc->write_oob = nand_write_oob_std;
- if (!ecc->read_subpage)
- ecc->read_subpage = nand_read_subpage;
- if (!ecc->write_subpage && ecc->hwctl && ecc->calculate)
- ecc->write_subpage = nand_write_subpage_hwecc;
- fallthrough;
-
- case NAND_ECC_PLACEMENT_INTERLEAVED:
- if ((!ecc->calculate || !ecc->correct || !ecc->hwctl) &&
- (!ecc->read_page ||
- ecc->read_page == nand_read_page_hwecc ||
- !ecc->write_page ||
- ecc->write_page == nand_write_page_hwecc)) {
- WARN(1, "No ECC functions supplied; hardware ECC not possible\n");
- ret = -EINVAL;
- goto err_nand_manuf_cleanup;
- }
- /* Use standard syndrome read/write page function? */
- if (!ecc->read_page)
- ecc->read_page = nand_read_page_syndrome;
- if (!ecc->write_page)
- ecc->write_page = nand_write_page_syndrome;
- if (!ecc->read_page_raw)
- ecc->read_page_raw = nand_read_page_raw_syndrome;
- if (!ecc->write_page_raw)
- ecc->write_page_raw = nand_write_page_raw_syndrome;
- if (!ecc->read_oob)
- ecc->read_oob = nand_read_oob_syndrome;
- if (!ecc->write_oob)
- ecc->write_oob = nand_write_oob_syndrome;
- break;
-
- default:
- pr_warn("Invalid NAND_ECC_PLACEMENT %d\n",
- ecc->placement);
- ret = -EINVAL;
+ ret = nand_set_ecc_on_host_ops(chip);
+ if (ret)
goto err_nand_manuf_cleanup;
- }
if (mtd->writesize >= ecc->size) {
if (!ecc->strength) {
--
2.25.1
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 2/3] mtd: rawnand: Introduce nand_set_ecc_on_host_ops()
2020-09-17 7:52 ` [PATCH 2/3] mtd: rawnand: Introduce nand_set_ecc_on_host_ops() Tudor Ambarus
@ 2020-09-28 15:00 ` Miquel Raynal
0 siblings, 0 replies; 7+ messages in thread
From: Miquel Raynal @ 2020-09-28 15:00 UTC (permalink / raw)
To: Tudor Ambarus, miquel.raynal, richard, vigneshr, boris.brezillon
Cc: linux-mtd, linux-kernel
On Thu, 2020-09-17 at 07:52:12 UTC, Tudor Ambarus wrote:
> There were too many levels of indentation and the code was
> hard to read. Introduce a new function, similar to
> nand_set_ecc_soft_ops().
>
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/3] mtd: rawnand: Don't overwrite the error code from nand_set_ecc_soft_ops()
2020-09-17 7:52 [PATCH 0/3] mtd: rawnand: Fix HW ECC handling Tudor Ambarus
2020-09-17 7:52 ` [PATCH 1/3] mtd: rawnand: Fix wrongful fallthrough NAND_ECC_SOFT Tudor Ambarus
2020-09-17 7:52 ` [PATCH 2/3] mtd: rawnand: Introduce nand_set_ecc_on_host_ops() Tudor Ambarus
@ 2020-09-17 7:52 ` Tudor Ambarus
2020-09-28 15:00 ` Miquel Raynal
2 siblings, 1 reply; 7+ messages in thread
From: Tudor Ambarus @ 2020-09-17 7:52 UTC (permalink / raw)
To: miquel.raynal, richard, vigneshr, boris.brezillon
Cc: linux-mtd, linux-kernel, Tudor Ambarus
The error code received from nand_set_ecc_soft_ops() was overwritten,
drop this redundant assignment and use the error code received from
the callee.
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
drivers/mtd/nand/raw/nand_base.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index d3e0ca66382f..78feed59c8b5 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -5698,10 +5698,8 @@ static int nand_scan_tail(struct nand_chip *chip)
case NAND_ECC_ENGINE_TYPE_SOFT:
ret = nand_set_ecc_soft_ops(chip);
- if (ret) {
- ret = -EINVAL;
+ if (ret)
goto err_nand_manuf_cleanup;
- }
break;
case NAND_ECC_ENGINE_TYPE_ON_DIE:
--
2.25.1
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 3/3] mtd: rawnand: Don't overwrite the error code from nand_set_ecc_soft_ops()
2020-09-17 7:52 ` [PATCH 3/3] mtd: rawnand: Don't overwrite the error code from nand_set_ecc_soft_ops() Tudor Ambarus
@ 2020-09-28 15:00 ` Miquel Raynal
0 siblings, 0 replies; 7+ messages in thread
From: Miquel Raynal @ 2020-09-28 15:00 UTC (permalink / raw)
To: Tudor Ambarus, miquel.raynal, richard, vigneshr, boris.brezillon
Cc: linux-mtd, linux-kernel
On Thu, 2020-09-17 at 07:52:13 UTC, Tudor Ambarus wrote:
> The error code received from nand_set_ecc_soft_ops() was overwritten,
> drop this redundant assignment and use the error code received from
> the callee.
>
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
^ permalink raw reply [flat|nested] 7+ messages in thread