Merge branch 'omap-for-v4.8/legacy' into for-next
[deliverable/linux.git] / drivers / mtd / nand / nand_bch.c
index b585bae379290f9993b127087d52fc9dc753eda8..44763f87eae494eccd65241d5b6774aba4527cf4 100644 (file)
 /**
  * struct nand_bch_control - private NAND BCH control structure
  * @bch:       BCH control structure
- * @ecclayout: private ecc layout for this BCH configuration
  * @errloc:    error location array
  * @eccmask:   XOR ecc mask, allows erased pages to be decoded as valid
  */
 struct nand_bch_control {
        struct bch_control   *bch;
-       struct nand_ecclayout ecclayout;
        unsigned int         *errloc;
        unsigned char        *eccmask;
 };
@@ -124,7 +122,6 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
 {
        struct nand_chip *nand = mtd_to_nand(mtd);
        unsigned int m, t, eccsteps, i;
-       struct nand_ecclayout *layout = nand->ecc.layout;
        struct nand_bch_control *nbc = NULL;
        unsigned char *erased_page;
        unsigned int eccsize = nand->ecc.size;
@@ -161,34 +158,10 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
 
        eccsteps = mtd->writesize/eccsize;
 
-       /* if no ecc placement scheme was provided, build one */
-       if (!layout) {
-
-               /* handle large page devices only */
-               if (mtd->oobsize < 64) {
-                       printk(KERN_WARNING "must provide an oob scheme for "
-                              "oobsize %d\n", mtd->oobsize);
-                       goto fail;
-               }
-
-               layout = &nbc->ecclayout;
-               layout->eccbytes = eccsteps*eccbytes;
-
-               /* reserve 2 bytes for bad block marker */
-               if (layout->eccbytes+2 > mtd->oobsize) {
-                       printk(KERN_WARNING "no suitable oob scheme available "
-                              "for oobsize %d eccbytes %u\n", mtd->oobsize,
-                              eccbytes);
-                       goto fail;
-               }
-               /* put ecc bytes at oob tail */
-               for (i = 0; i < layout->eccbytes; i++)
-                       layout->eccpos[i] = mtd->oobsize-layout->eccbytes+i;
-
-               layout->oobfree[0].offset = 2;
-               layout->oobfree[0].length = mtd->oobsize-2-layout->eccbytes;
-
-               nand->ecc.layout = layout;
+       /* Check that we have an oob layout description. */
+       if (!mtd->ooblayout) {
+               pr_warn("missing oob scheme");
+               goto fail;
        }
 
        /* sanity checks */
@@ -196,7 +169,18 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
                printk(KERN_WARNING "eccsize %u is too large\n", eccsize);
                goto fail;
        }
-       if (layout->eccbytes != (eccsteps*eccbytes)) {
+
+       /*
+        * ecc->steps and ecc->total might be used by mtd->ooblayout->ecc(),
+        * which is called by mtd_ooblayout_count_eccbytes().
+        * Make sure they are properly initialized before calling
+        * mtd_ooblayout_count_eccbytes().
+        * FIXME: we should probably rework the sequencing in nand_scan_tail()
+        * to avoid setting those fields twice.
+        */
+       nand->ecc.steps = eccsteps;
+       nand->ecc.total = eccsteps * eccbytes;
+       if (mtd_ooblayout_count_eccbytes(mtd) != (eccsteps*eccbytes)) {
                printk(KERN_WARNING "invalid ecc layout\n");
                goto fail;
        }
This page took 0.024481 seconds and 5 git commands to generate.