[PATCH 2/5] backport mtd api change to mtd infrastructure

Artem Bityutskiy dedekind1 at gmail.com
Thu Dec 1 03:59:09 EST 2011


On Mon, 2011-11-28 at 17:02 -0800, Mike Dunn wrote:
> diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
> index 7c1dc90..ada714d 100644
> --- a/drivers/mtd/mtdblock.c
> +++ b/drivers/mtd/mtdblock.c
> @@ -182,10 +182,13 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
>  
>  			if (mtdblk->cache_state == STATE_EMPTY ||
>  			    mtdblk->cache_offset != sect_start) {
> +				unsigned int max_bitflips;
> +
>  				/* fill the cache with the current sector */
>  				mtdblk->cache_state = STATE_EMPTY;
>  				ret = mtd->read(mtd, sect_start, sect_size,
> -						&retlen, mtdblk->cache_data);
> +						&retlen, mtdblk->cache_data,
> +						&max_bitflips);

Now difficult would it be to allow for NULL to be passed as the last
argument? I think it makes sense to do so that the callers who do not
care about the max. bit-flips just pass NULL and they would not have to
define an dummy 'int max_bitflips' variable which they do not need at
all. And the amount of changes you introduce would be smaller.

E.g. in this case, you would just add on NULL argument to mtd->read.

Probably the implementations would need to do something like this:

int tmp;

if (!max_bitflips)
	max_bitflips = &tmp;

So it does not seem to be difficult to implement.

> -			ret = mtd->read(mtd, *ppos, len, &retlen, kbuf);
> +			ret = mtd->read(mtd, *ppos, len, &retlen, kbuf,
> +					&max_bitflips);
>  		}
>  		/* Nand returns -EBADMSG on ECC errors, but it returns
>  		 * the data. For our userspace tools it is important
>  		 * to dump areas with ECC errors!
>  		 * For kernel internal usage it also might return -EUCLEAN
> -		 * to signal the caller that a bitflip has occurred and has
> -		 * been corrected by the ECC algorithm.
> +		 * to signal the caller that one or more bitflips have occurred
> +		 * and have been corrected by the ECC algorithm.  The highest
> +		 * number of corrected bits in a single page is returned in the
> +		 * max_bitflips arg.

If you do what I proposed you won't need to change the comment here and
in mtd_do_readoob().

Artem.




More information about the linux-mtd mailing list