public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: "Jörn Engel" <joern@logfs.org>
To: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Cc: dwmw2@infradead.org, akpm@linux-foundation.org,
	linux-mtd@lists.infradead.org
Subject: Re: [PATCH 1/2] mtdpart: Avoid divide-by-zero on out-of-reach path
Date: Wed, 18 Jun 2008 19:54:16 +0200	[thread overview]
Message-ID: <20080618175416.GF10271@logfs.org> (raw)
In-Reply-To: <20080618175342.GE10271@logfs.org>

[PATCH 3/4] [MTD][MTDPART] Cleanup and document the erase region handling

Mostly simplifying the loops.  Now everything fits into 80 columns,
is easier to read and the finer details have extra comments.

Signed-off-by: Joern Engel <joern@logfs.org>
---
 drivers/mtd/mtdpart.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index e759ee6..c1a8916 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -433,18 +433,24 @@ static int add_one_partition(struct mtd_info *master,
 	}
 	if (master->numeraseregions > 1) {
 		/* Deal with variable erase size stuff */
-		int i;
+		int i, max = master->numeraseregions;
+		u32 end = slave->offset + slave->mtd.size;
 		struct mtd_erase_region_info *regions = master->eraseregions;
 
-		/* Find the first erase regions which is part of this partition. */
-		for (i = 0; i < master->numeraseregions && regions[i].offset <= slave->offset; i++)
+		/* Find the first erase regions which is part of this
+		 * partition. */
+		for (i = 0; i < max && regions[i].offset <= slave->offset; i++)
 			;
+		/* The loop searched for the region _behind_ the first one */
+		i--;
 
-		for (i--; i < master->numeraseregions && regions[i].offset < slave->offset + slave->mtd.size; i++) {
+		/* Pick biggest erasesize */
+		for (; i < max && regions[i].offset < end; i++) {
 			if (slave->mtd.erasesize < regions[i].erasesize) {
 				slave->mtd.erasesize = regions[i].erasesize;
 			}
 		}
+		BUG_ON(slave->mtd.erasesize == 0);
 	} else {
 		/* Single erase size */
 		slave->mtd.erasesize = master->erasesize;
-- 
1.5.3.5

  reply	other threads:[~2008-06-18 17:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-16 14:32 [PATCH 1/2] mtdpart: Avoid divide-by-zero on out-of-reach path Atsushi Nemoto
2008-06-17 15:29 ` Jörn Engel
2008-06-17 15:39   ` Jörn Engel
2008-06-17 16:15     ` Atsushi Nemoto
2008-06-17 15:57   ` Atsushi Nemoto
2008-06-17 16:46     ` Jörn Engel
2008-06-18  2:19       ` Atsushi Nemoto
2008-06-18 17:40         ` Jörn Engel
2008-06-18 17:52           ` Jörn Engel
2008-06-18 17:53             ` Jörn Engel
2008-06-18 17:54               ` Jörn Engel [this message]
2008-06-18 17:54                 ` Jörn Engel
2008-06-19  7:09             ` Atsushi Nemoto
2008-06-19  8:24               ` Jörn Engel
2008-06-19  8:34                 ` Atsushi Nemoto
2008-07-16 15:10                   ` Atsushi Nemoto
2008-07-17 14:55                     ` Jörn Engel
2008-07-18 15:47                       ` Atsushi Nemoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080618175416.GF10271@logfs.org \
    --to=joern@logfs.org \
    --cc=akpm@linux-foundation.org \
    --cc=anemo@mba.ocn.ne.jp \
    --cc=dwmw2@infradead.org \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox