[PATCH 1/2] mtdpart: Avoid divide-by-zero on out-of-reach path

Jörn Engel joern at logfs.org
Tue Jun 17 12:46:29 EDT 2008


On Wed, 18 June 2008 00:57:35 +0900, Atsushi Nemoto wrote:
> 
> > Odd.  And the second loop should go backwards as long as the
> > eraseregions are part of the current partition.  Which means that
> > 	i < master->numeraseregions
> > doesn't make sense at all and
> > 	slave->offset + slave->mtd.size > regions[i].offset
> > would imply that eraseregions go backwards.
> 
> No, the second loop go forwards.  It searches maximum erasesize of the
> partition.

Indeed, it does.  And if I change the order in the conditions, those
make sense even to me.  Hm.

But what purpose does the 'i--' serve?  Why would we want to check an
eraseregion _before_ the start of the partition?

Next, you could simply add code like this below the second loop:
	/* In case no eraseregion matched. */
	if (slave->mtd.erasesize == 0)
		slave->mtd.erasesize = master->erasesize;

But under which conditions would we ever run into this?  It appears as
if those conditions would be better served with either 'BUG();' or
'return -EINVAL;'.

I am still rather confused by all this.

Jörn

-- 
...one more straw can't possibly matter...
-- Kirby Bakken



More information about the linux-mtd mailing list