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

Atsushi Nemoto anemo at mba.ocn.ne.jp
Tue Jun 17 11:57:35 EDT 2008


On Tue, 17 Jun 2008 17:29:32 +0200, Jörn Engel <joern at logfs.org> wrote:
> At least I have a hard enough time understanding it today.  The first
> loop seems to look for the last eraseregion that is part of the current
> partition.  Why then it should check for
> 	slave->offset + slave->mtd.size > regions[i].offset
> instead of 
> 	slave->offset >= regions[i].offset

The first loop searches an erase region which the start of the
partition belongs to.  So slave->mtd.size should be irrelevant.

> 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.

> In other words, I am tempted to replace all that with a single line:
> 	BUG();
> 
> At least that line is short and descriptive.  Otherwise it seems to be
> roughly equivalent of what we had before.

Oh please don't.  Creating partitions on NOR flash chip with small
boot sectors is common usage.  These codes are surely required.

---
Atsushi Nemoto



More information about the linux-mtd mailing list