All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jörn Engel" <joern@logfs.org>
To: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Cc: David Woodhouse <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: Tue, 17 Jun 2008 17:29:32 +0200	[thread overview]
Message-ID: <20080617152932.GD28448@logfs.org> (raw)
In-Reply-To: <20080616.233222.112854616.anemo@mba.ocn.ne.jp>

On Mon, 16 June 2008 23:32:22 +0900, Atsushi Nemoto wrote:
> 
>  
> -			for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
> +			i--;
> +			slave->mtd.erasesize = regions[i].erasesize;
> +			for (; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
>  				if (slave->mtd.erasesize < regions[i].erasesize) {
>  					slave->mtd.erasesize = regions[i].erasesize;
>  				}

While this patch appears to work, I still don't like it.  Before the
patch, the whole function is simply a mess.  After your patch, it looks
even worse and becomes almost impossible to understand.  So while you
are fixing a bug today, the very next change may introduce a new bug
simply because whoever makes the change doesn't understand the code.

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

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.

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.

Jörn

-- 
Mundie uses a textbook tactic of manipulation: start with some
reasonable talk, and lead the audience to an unreasonable conclusion.
-- Bruce Perens

  reply	other threads:[~2008-06-17 15:29 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 [this message]
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
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=20080617152932.GD28448@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.