[PATCH 4/8] mtd: Add support for emulated SLC mode on MLC NANDs

Miquel Raynal miquel.raynal at bootlin.com
Tue Jan 14 02:04:13 PST 2020


Hi Richard,

A very simple question below.

> 
> > +	 * is an MLC NAND and has a proper pairing scheme defined.
> > +	 * We also reject masters that implement ->_writev() for now, because
> > +	 * NAND controller drivers don't implement this hook, and adding the
> > +	 * SLC -> MLC address/length conversion to this path is useless if we
> > +	 * don't have a user.
> > +	 */
> > +	if (mtd->flags & MTD_MLC_IN_SLC_MODE &&
> > +	    (!mtd_is_partition(mtd) || master->type != MTD_MLCNANDFLASH ||
> > +	     !master->pairing || master->_writev))
> > +		return -EINVAL;
> > +
> > 	mutex_lock(&mtd_table_mutex);
> > 
> > 	i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
> > @@ -632,6 +645,14 @@ int add_mtd_device(struct mtd_info *mtd)
> > 	if (mtd->bitflip_threshold == 0)
> > 		mtd->bitflip_threshold = mtd->ecc_strength;
> > 
> > +	if (mtd->flags & MTD_MLC_IN_SLC_MODE) {
> > +		int ngroups = mtd_pairing_groups(master);
> > +
> > +		mtd->erasesize /= ngroups;
> > +		mtd->size = (u64)mtd_div_by_eb(mtd->size, master) *
> > +			    mtd->erasesize;  
> 
> Can we please have a helper for this? You use this formula many times.

I thought you were talking about the mtd->size calculation but this
line appears only once as-is. the whole 'if' block is never exactly the
same so it cannot be factored out. The only line that is actually
repeating is the if condition. Do you mean you would like something
like this?

	static bool mtd_emulates_slc(struct mtd_info *mtd)
	{
		return mtd->flags & MTD_EMULATE_SLC_ON_MLC;
	}


Thanks,
Miquèl



More information about the linux-mtd mailing list