Re: [linux-sunxi] [PATCH 01/23] mtd: kill the ecclayout->oobavail field

From: Boris Brezillon
Date: Tue Dec 08 2015 - 03:15:08 EST


Hi Priit,

On Tue, 08 Dec 2015 08:43:05 +0200
Priit Laes <plaes@xxxxxxxxx> wrote:

> On Mon, 2015-12-07 at 23:25 +0100, Boris Brezillon wrote:
> > ecclayout->oobavail is just redundant with the mtd->oobavail field.
> > Moreover, it prevents static const definition of ecc layouts since
> > the
> > NAND framework is calculating this value based on the ecclayout-
> > >oobfree
> > field.
> >
> > Signed-off-by: Boris Brezillon <boris.brezillon@xxxxxxxxxxxxxxxxxx>
> > ---
> > Âdrivers/mtd/devices/docg3.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂ5 ++-
> > Âdrivers/mtd/mtdswap.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ| 16 ++++-----
> > Âdrivers/mtd/nand/brcmnand/brcmnand.cÂÂÂÂÂÂÂÂÂÂ|ÂÂ3 --
> > Âdrivers/mtd/nand/docg4.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂ1 -
> > Âdrivers/mtd/nand/hisi504_nand.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂ1 -
> > Âdrivers/mtd/nand/nand_base.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ| 12 +++----
> > Âdrivers/mtd/onenand/onenand_base.cÂÂÂÂÂÂÂÂÂÂÂÂ| 16 ++++-----
> > Âdrivers/mtd/tests/oobtest.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ| 49 +++++++++++++--
> > ------------
> > Âdrivers/staging/mt29f_spinand/mt29f_spinand.c |ÂÂ1 -
> > Âfs/jffs2/wbuf.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂ6 ++--
> > Âinclude/linux/mtd/mtd.hÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂ1 -
> > Â11 files changed, 48 insertions(+), 63 deletions(-)
> >
> [..]
> > Â
> > diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c
> > b/drivers/mtd/nand/brcmnand/brcmnand.c
> > index 35d78f7..a906ec2 100644
> > --- a/drivers/mtd/nand/brcmnand/brcmnand.c
> > +++ b/drivers/mtd/nand/brcmnand/brcmnand.c
> > @@ -845,9 +845,6 @@ static struct nand_ecclayout *brcmnand_create_layout(int ecc_level,
> > Â break;
> > Â }
> > Âout:
> > - /* Sum available OOB */
> > - for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES_LARGE; i++)
> > - layout->oobavail += layout->oobfree[i].length;
> > Â return layout;
> > Â}
>
> You can get rid of the 'out' label and replace the single goto in this
> function with 'return layout'.

Yep, I'll fix that.

>
> [...]
> > Â
> > diff --git a/drivers/mtd/nand/nand_base.c
> > b/drivers/mtd/nand/nand_base.c
> > index 0748a13..1107f5c1 100644
> > --- a/drivers/mtd/nand/nand_base.c
> > +++ b/drivers/mtd/nand/nand_base.c
> > @@ -2037,7 +2037,7 @@ static int nand_do_read_oob(struct mtd_info
> > *mtd, loff_t from,
> > Â stats = mtd->ecc_stats;
> > Â
> > Â if (ops->mode == MTD_OPS_AUTO_OOB)
> > - len = chip->ecc.layout->oobavail;
> > + len = mtd->oobavail;
> > Â else
> > Â len = mtd->oobsize;
> > Â
> > @@ -2728,7 +2728,7 @@ static int nand_do_write_oob(struct mtd_info
> > *mtd, loff_t to,
> > Â Â__func__, (unsigned int)to, (int)ops-
> > >ooblen);
> > Â
> > Â if (ops->mode == MTD_OPS_AUTO_OOB)
> > - len = chip->ecc.layout->oobavail;
> > + len = mtd->oobavail;
> > Â else
> > Â len = mtd->oobsize;
> > Â
> [...]
> > diff --git a/drivers/mtd/onenand/onenand_base.c
> > b/drivers/mtd/onenand/onenand_base.c
> > index 43b3392..d70bbfd 100644
> > --- a/drivers/mtd/onenand/onenand_base.c
> > +++ b/drivers/mtd/onenand/onenand_base.c
> > @@ -1125,7 +1125,7 @@ static int onenand_mlc_read_ops_nolock(struct
> > mtd_info *mtd, loff_t from,
> > Â (int)len);
> > Â
> > Â if (ops->mode == MTD_OPS_AUTO_OOB)
> > - oobsize = this->ecclayout->oobavail;
> > + oobsize = mtd->oobavail;
> > Â else
> > Â oobsize = mtd->oobsize;
> > Â
> > @@ -1230,7 +1230,7 @@ static int onenand_read_ops_nolock(struct
> > mtd_info *mtd, loff_t from,
> > Â (int)len);
> > Â
> > Â if (ops->mode == MTD_OPS_AUTO_OOB)
> > - oobsize = this->ecclayout->oobavail;
> > + oobsize = mtd->oobavail;
> > Â else
> > Â oobsize = mtd->oobsize;
> > Â
> > @@ -1365,7 +1365,7 @@ static int onenand_read_oob_nolock(struct
> > mtd_info *mtd, loff_t from,
> > Â ops->oobretlen = 0;
> > Â
> > Â if (mode == MTD_OPS_AUTO_OOB)
> > - oobsize = this->ecclayout->oobavail;
> > + oobsize = mtd->oobavail;
> > Â else
> > Â oobsize = mtd->oobsize;
> > Â
> > @@ -1887,7 +1887,7 @@ static int onenand_write_ops_nolock(struct
> > mtd_info *mtd, loff_t to,
> > Â return 0;
> > Â
> > Â if (ops->mode == MTD_OPS_AUTO_OOB)
> > - oobsize = this->ecclayout->oobavail;
> > + oobsize = mtd->oobavail;
> > Â else
> > Â oobsize = mtd->oobsize;
> > Â
> > @@ -2063,7 +2063,7 @@ static int onenand_write_oob_nolock(struct
> > mtd_info *mtd, loff_t to,
> > Â ops->oobretlen = 0;
> > Â
> > Â if (mode == MTD_OPS_AUTO_OOB)
> > - oobsize = this->ecclayout->oobavail;
> > + oobsize = mtd->oobavail;
> > Â else
> > Â oobsize = mtd->oobsize;
>
> This identical construction seems to occur multiple times in multiple
> files. Would it make sense to create a macro for it?

Right, I'll make another patch move this logic into an inline function.

Thanks for the review.

Boris


--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/