[PATCH] MTD: fix dataflash 64-bit divisions

David Brownell david-b at pacbell.net
Wed Dec 17 12:47:38 EST 2008


On Wednesday 17 December 2008, Nicolas Pitre wrote:
> On Wed, 17 Dec 2008, Artem Bityutskiy wrote:
> 
> > -	if ((instr->addr + instr->len) > mtd->size
> > -			|| (instr->len % priv->page_size) != 0
> > -			|| (instr->addr % priv->page_size) != 0)
> > +	if (instr->addr + instr->len > mtd->size)
> > +		return -EINVAL;
> > +	tmp = instr->len;
> > +	if (do_div(tmp, priv->page_size))
> > +		return -EINVAL;
> > +	tmp = instr->addr;
> > +	if (do_div(tmp, priv->page_size))
> >  		return -EINVAL;
> 
> Is it possible to have priv->page_size not a power of two?

Yes, and in fact it's probably more common to have some
extra bytes at the end of a page.  See the table right
before dataflash_probe(); the one before jedec_probe()
lists parts that can be made to use binary page sizes.

If these were NAND chips you'd think of it as OOB area ...
except it's addressible the normal way.  In particular,
the common "read all bytes starting at page N" operation
include those extra bytes.  And you *do* want to use
those primitives, to avoid a roundtrip over SPI for each
1056 or 528 (etc) page.



More information about the linux-mtd mailing list