[PATCH] MTD: fix dataflash 64-bit divisions
Nicolas Pitre
nico at cam.org
Wed Dec 17 12:15:46 EST 2008
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? If no then
the above test is becoming rather costly, and something like:
if ((instr->len | instr->addr) & (priv->page_size - 1))
return -EINVAL;
would be much cheaper.
> - pageaddr = instr->addr / priv->page_size;
> + tmp = instr->len;
> + do_div(tmp, priv->page_size);
> + pageaddr = tmp;
Here I suggest you include <linux/math64.h> and use this instead:
pageaddr = div_u64(instr->addr, priv->page_size);
Nicolas
More information about the linux-mtd
mailing list