mtd: spinand: Allow the case where there is no ECC engine
authorMiquel Raynal <miquel.raynal@bootlin.com>
Thu, 1 Oct 2020 10:20:12 +0000 (12:20 +0200)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Thu, 10 Dec 2020 21:37:30 +0000 (22:37 +0100)
Even if this is not supposed to happen, there is no reason to fail the
probe if it was explicitly requested to use no ECC engine at all (for
instance, during development). This condition is met by just
commenting out the error on the OOB free bytes count after the
assignation of an ECC engine if none was provided (any other situation
would error out much earlier anyway).

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20201001102014.20100-5-miquel.raynal@bootlin.com
drivers/mtd/nand/ecc.c
drivers/mtd/nand/spi/core.c

index 9afdde70824a53140b2ac8dd3610f4a5b6684438..6c43dfda01d4ddd7094414ebba8d39cebffdf327 100644 (file)
  */
 int nand_ecc_init_ctx(struct nand_device *nand)
 {
-       if (!nand->ecc.engine->ops->init_ctx)
+       if (!nand->ecc.engine || !nand->ecc.engine->ops->init_ctx)
                return 0;
 
        return nand->ecc.engine->ops->init_ctx(nand);
@@ -118,7 +118,7 @@ EXPORT_SYMBOL(nand_ecc_init_ctx);
  */
 void nand_ecc_cleanup_ctx(struct nand_device *nand)
 {
-       if (nand->ecc.engine->ops->cleanup_ctx)
+       if (nand->ecc.engine && nand->ecc.engine->ops->cleanup_ctx)
                nand->ecc.engine->ops->cleanup_ctx(nand);
 }
 EXPORT_SYMBOL(nand_ecc_cleanup_ctx);
@@ -131,7 +131,7 @@ EXPORT_SYMBOL(nand_ecc_cleanup_ctx);
 int nand_ecc_prepare_io_req(struct nand_device *nand,
                            struct nand_page_io_req *req)
 {
-       if (!nand->ecc.engine->ops->prepare_io_req)
+       if (!nand->ecc.engine || !nand->ecc.engine->ops->prepare_io_req)
                return 0;
 
        return nand->ecc.engine->ops->prepare_io_req(nand, req);
@@ -146,7 +146,7 @@ EXPORT_SYMBOL(nand_ecc_prepare_io_req);
 int nand_ecc_finish_io_req(struct nand_device *nand,
                           struct nand_page_io_req *req)
 {
-       if (!nand->ecc.engine->ops->finish_io_req)
+       if (!nand->ecc.engine || !nand->ecc.engine->ops->finish_io_req)
                return 0;
 
        return nand->ecc.engine->ops->finish_io_req(nand, req);
index 8a4d20e30edb6b6db6fb7f583e10f78588ff9956..4a4c86d8eeb6a2c7ad4358ab0afa6adbf530d341 100644 (file)
@@ -1160,9 +1160,11 @@ static int spinand_init(struct spinand_device *spinand)
        mtd->_erase = spinand_mtd_erase;
        mtd->_max_bad_blocks = nanddev_mtd_max_bad_blocks;
 
-       ret = mtd_ooblayout_count_freebytes(mtd);
-       if (ret < 0)
-               goto err_cleanup_ecc_engine;
+       if (nand->ecc.engine) {
+               ret = mtd_ooblayout_count_freebytes(mtd);
+               if (ret < 0)
+                       goto err_cleanup_ecc_engine;
+       }
 
        mtd->oobavail = ret;