4.17-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Boris Brezillon <boris.brezil...@bootlin.com>

commit 782d1967d0479ffd59412b2f3179c8bb35f50ff6 upstream.

The ONFI spec clearly says that FAIL bit is only valid for PROGRAM,
ERASE and READ-with-on-die-ECC operations, and should be ignored
otherwise.

It seems that checking it after sending a SET_FEATURES is a bad idea
because a previous READ, PROGRAM or ERASE op may have failed, and
depending on the implementation, the FAIL bit is not cleared until a
new READ, PROGRAM or ERASE is started.

This leads to ->set_features() returning -EIO while it actually worked,
which can sometimes stop a batch of READ/PROGRAM ops.

Note that we only fix the ->exec_op() path here, because some drivers
are abusing the NAND_STATUS_FAIL flag in their ->waitfunc()
implementation to propagate other kind of errors, like
wait-ready-timeout or controller-related errors. Let's not try to fix
those drivers since they worked fine so far.

Fixes: 8878b126df76 ("mtd: nand: add ->exec_op() implementation")
Cc: sta...@vger.kernel.org
Signed-off-by: Boris Brezillon <boris.brezil...@bootlin.com>
Acked-by: Miquel Raynal <miquel.ray...@bootlin.com>
Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>

---
 drivers/mtd/nand/raw/nand_base.c |   29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -2174,7 +2174,6 @@ static int nand_set_features_op(struct n
        struct mtd_info *mtd = nand_to_mtd(chip);
        const u8 *params = data;
        int i, ret;
-       u8 status;
 
        if (chip->exec_op) {
                const struct nand_sdr_timings *sdr =
@@ -2188,26 +2187,18 @@ static int nand_set_features_op(struct n
                };
                struct nand_operation op = NAND_OPERATION(instrs);
 
-               ret = nand_exec_op(chip, &op);
-               if (ret)
-                       return ret;
-
-               ret = nand_status_op(chip, &status);
-               if (ret)
-                       return ret;
-       } else {
-               chip->cmdfunc(mtd, NAND_CMD_SET_FEATURES, feature, -1);
-               for (i = 0; i < ONFI_SUBFEATURE_PARAM_LEN; ++i)
-                       chip->write_byte(mtd, params[i]);
-
-               ret = chip->waitfunc(mtd, chip);
-               if (ret < 0)
-                       return ret;
-
-               status = ret;
+               return nand_exec_op(chip, &op);
        }
 
-       if (status & NAND_STATUS_FAIL)
+       chip->cmdfunc(mtd, NAND_CMD_SET_FEATURES, feature, -1);
+       for (i = 0; i < ONFI_SUBFEATURE_PARAM_LEN; ++i)
+               chip->write_byte(mtd, params[i]);
+
+       ret = chip->waitfunc(mtd, chip);
+       if (ret < 0)
+               return ret;
+
+       if (ret & NAND_STATUS_FAIL)
                return -EIO;
 
        return 0;


Reply via email to