diff options
author | Miquel Raynal <miquel.raynal@bootlin.com> | 2020-09-30 01:01:08 +0200 |
---|---|---|
committer | Miquel Raynal <miquel.raynal@bootlin.com> | 2020-11-30 09:27:32 +0100 |
commit | 3c0fe36abebee55821badaa9d6cecd03799f7843 (patch) | |
tree | af49ac5fef58f27190c57d8386ed205ea16a3f99 /drivers | |
parent | 8c5c209218564a180e8b90fb12d29f72485c6c72 (diff) |
mtd: nand: ecc-bch: Stop exporting the private structure
The NAND BCH control structure has nothing to do outside of this
driver, all users of the nand_bch_init/free() functions just save it
to chip->ecc.priv so do it in this driver directly and return a
regular error code instead.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20200929230124.31491-5-miquel.raynal@bootlin.com
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mtd/nand/ecc-sw-bch.c | 38 | ||||
-rw-r--r-- | drivers/mtd/nand/raw/fsmc_nand.c | 2 | ||||
-rw-r--r-- | drivers/mtd/nand/raw/nand_base.c | 12 | ||||
-rw-r--r-- | drivers/mtd/nand/raw/omap2.c | 16 |
4 files changed, 37 insertions, 31 deletions
diff --git a/drivers/mtd/nand/ecc-sw-bch.c b/drivers/mtd/nand/ecc-sw-bch.c index f98a03e8efae..b6bfee9805ae 100644 --- a/drivers/mtd/nand/ecc-sw-bch.c +++ b/drivers/mtd/nand/ecc-sw-bch.c @@ -90,7 +90,7 @@ EXPORT_SYMBOL(nand_bch_correct_data); /** * nand_bch_init - Initialize software BCH ECC engine - * @mtd: MTD device + * @chip: NAND chip object * * Returns: a pointer to a new NAND BCH control structure, or NULL upon failure * @@ -105,24 +105,24 @@ EXPORT_SYMBOL(nand_bch_correct_data); * @eccsize = 512 (thus, m = 13 is the smallest integer such that 2^m - 1 > 512 * 8) * @eccbytes = 7 (7 bytes are required to store m * t = 13 * 4 = 52 bits) */ -struct nand_bch_control *nand_bch_init(struct mtd_info *mtd) +int nand_bch_init(struct nand_chip *chip) { - struct nand_chip *nand = mtd_to_nand(mtd); + struct mtd_info *mtd = nand_to_mtd(chip); unsigned int m, t, eccsteps, i; struct nand_bch_control *nbc = NULL; unsigned char *erased_page; - unsigned int eccsize = nand->ecc.size; - unsigned int eccbytes = nand->ecc.bytes; - unsigned int eccstrength = nand->ecc.strength; + unsigned int eccsize = chip->ecc.size; + unsigned int eccbytes = chip->ecc.bytes; + unsigned int eccstrength = chip->ecc.strength; if (!eccbytes && eccstrength) { eccbytes = DIV_ROUND_UP(eccstrength * fls(8 * eccsize), 8); - nand->ecc.bytes = eccbytes; + chip->ecc.bytes = eccbytes; } if (!eccsize || !eccbytes) { pr_warn("ecc parameters not supplied\n"); - goto fail; + return -EINVAL; } m = fls(1+8*eccsize); @@ -130,7 +130,9 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd) nbc = kzalloc(sizeof(*nbc), GFP_KERNEL); if (!nbc) - goto fail; + return -ENOMEM; + + chip->ecc.priv = nbc; nbc->bch = bch_init(m, t, 0, false); if (!nbc->bch) @@ -165,9 +167,9 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd) * 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; - nand->base.ecc.ctx.total = nand->ecc.total; + chip->ecc.steps = eccsteps; + chip->ecc.total = eccsteps * eccbytes; + nand->base.ecc.ctx.total = chip->ecc.total; if (mtd_ooblayout_count_eccbytes(mtd) != (eccsteps*eccbytes)) { pr_warn("invalid ecc layout\n"); goto fail; @@ -193,12 +195,12 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd) nbc->eccmask[i] ^= 0xff; if (!eccstrength) - nand->ecc.strength = (eccbytes * 8) / fls(8 * eccsize); + chip->ecc.strength = (eccbytes * 8) / fls(8 * eccsize); - return nbc; + return 0; fail: - nand_bch_free(nbc); - return NULL; + nand_bch_free(chip); + return -EINVAL; } EXPORT_SYMBOL(nand_bch_init); @@ -206,8 +208,10 @@ EXPORT_SYMBOL(nand_bch_init); * nand_bch_free - Release NAND BCH ECC resources * @nbc: NAND BCH control structure */ -void nand_bch_free(struct nand_bch_control *nbc) +void nand_bch_free(struct nand_chip *chip) { + struct nand_bch_control *nbc = chip->ecc.priv; + if (nbc) { bch_free(nbc->bch); kfree(nbc->errloc); diff --git a/drivers/mtd/nand/raw/fsmc_nand.c b/drivers/mtd/nand/raw/fsmc_nand.c index c88421a1c078..984b05e6bd38 100644 --- a/drivers/mtd/nand/raw/fsmc_nand.c +++ b/drivers/mtd/nand/raw/fsmc_nand.c @@ -942,7 +942,7 @@ static int fsmc_nand_attach_chip(struct nand_chip *nand) /* * Don't set layout for BCH4 SW ECC. This will be - * generated later in nand_bch_init() later. + * generated later during BCH initialization. */ if (nand->ecc.engine_type == NAND_ECC_ENGINE_TYPE_ON_HOST) { switch (mtd->oobsize) { diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 7edcf08a2e81..287c521a3d43 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -5203,6 +5203,7 @@ static int nand_set_ecc_soft_ops(struct nand_chip *chip) struct mtd_info *mtd = nand_to_mtd(chip); struct nand_device *nanddev = mtd_to_nanddev(mtd); struct nand_ecc_ctrl *ecc = &chip->ecc; + int ret; if (WARN_ON(ecc->engine_type != NAND_ECC_ENGINE_TYPE_SOFT)) return -EINVAL; @@ -5289,13 +5290,14 @@ static int nand_set_ecc_soft_ops(struct nand_chip *chip) ecc->strength = bytes * 8 / fls(8 * ecc->size); } - /* See nand_bch_init() for details. */ + /* See the software BCH ECC initialization for details */ ecc->bytes = 0; - ecc->priv = nand_bch_init(mtd); - if (!ecc->priv) { + ret = nand_bch_init(chip); + if (ret) { WARN(1, "BCH ECC initialization failed!\n"); - return -EINVAL; + return ret; } + return 0; default: WARN(1, "Unsupported ECC algorithm!\n"); @@ -5955,7 +5957,7 @@ void nand_cleanup(struct nand_chip *chip) { if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_SOFT && chip->ecc.algo == NAND_ECC_ALGO_BCH) - nand_bch_free((struct nand_bch_control *)chip->ecc.priv); + nand_bch_free(chip); nanddev_cleanup(&chip->base); diff --git a/drivers/mtd/nand/raw/omap2.c b/drivers/mtd/nand/raw/omap2.c index 0ef209e1cd87..6aab57336690 100644 --- a/drivers/mtd/nand/raw/omap2.c +++ b/drivers/mtd/nand/raw/omap2.c @@ -2047,10 +2047,10 @@ static int omap_nand_attach_chip(struct nand_chip *chip) /* Reserve one byte for the OMAP marker */ oobbytes_per_step = chip->ecc.bytes + 1; /* Software BCH library is used for locating errors */ - chip->ecc.priv = nand_bch_init(mtd); - if (!chip->ecc.priv) { + err = nand_bch_init(chip); + if (err) { dev_err(dev, "Unable to use BCH library\n"); - return -EINVAL; + return err; } break; @@ -2089,10 +2089,10 @@ static int omap_nand_attach_chip(struct nand_chip *chip) /* Reserve one byte for the OMAP marker */ oobbytes_per_step = chip->ecc.bytes + 1; /* Software BCH library is used for locating errors */ - chip->ecc.priv = nand_bch_init(mtd); - if (!chip->ecc.priv) { + err = nand_bch_init(chip); + if (err) { dev_err(dev, "unable to use BCH library\n"); - return -EINVAL; + return err; } break; @@ -2272,7 +2272,7 @@ return_error: if (!IS_ERR_OR_NULL(info->dma)) dma_release_channel(info->dma); if (nand_chip->ecc.priv) { - nand_bch_free(nand_chip->ecc.priv); + nand_bch_free(nand_chip); nand_chip->ecc.priv = NULL; } return err; @@ -2286,7 +2286,7 @@ static int omap_nand_remove(struct platform_device *pdev) int ret; if (nand_chip->ecc.priv) { - nand_bch_free(nand_chip->ecc.priv); + nand_bch_free(nand_chip); nand_chip->ecc.priv = NULL; } if (info->dma) |