All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: peter.crosthwaite@xilinx.com
Cc: Kevin Wolf <kwolf@redhat.com>,
	peter.maydell@linaro.org, qemu-trivial@nongnu.org,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
	edgar.iglesias@gmail.com
Subject: Re: [Qemu-trivial] [PATCH v1 1/5] block/nand: Factor out common code
Date: Wed, 19 Jun 2013 12:09:57 +0400	[thread overview]
Message-ID: <51C16755.9050700@msgid.tls.msk.ru> (raw)
In-Reply-To: <f65ba24ae67c04af46940c8cc67093894af97871.1371553360.git.peter.crosthwaite@xilinx.com>

18.06.2013 15:08, peter.crosthwaite@xilinx.com wrote:
> From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> 
> Most of this computation of s->iolen is the same for both the if and
> else paths here. Factor out the common parts outside the if.
> 
> Cc: qemu-trivial@nongnu.org
> 
> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> ---
> 
>  hw/block/nand.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/block/nand.c b/hw/block/nand.c
> index 087ca14..6309f93 100644
> --- a/hw/block/nand.c
> +++ b/hw/block/nand.c
> @@ -272,10 +272,10 @@ static void nand_command(NANDFlashState *s)
>              break;
>          offset = s->addr & ((1 << s->addr_shift) - 1);
>          s->blk_load(s, s->addr, offset);
> -        if (s->gnd)
> -            s->iolen = (1 << s->page_shift) - offset;
> -        else
> -            s->iolen = (1 << s->page_shift) + (1 << s->oob_shift) - offset;
> +        s->iolen = (1 << s->page_shift) - offset;
> +        if (!s->gnd) {
> +            s->iolen += 1 << s->oob_shift;
> +        }

Hm.  Can s->iolen become negative here?

addr_shift can be either less or greather than page_shift.  When addr_shift
is larger than page_shift (addr_shift=16, page_shift=11), offset may be up
to 65535, in which case s->iolen may be -63487, even without additional
oob_shift.

I dunno if this is a concern, just.. asking.

Besides, exactly the same expression is used in nand_getio() down this file,
maybe a common function is in order? :)

And looking at this file, I think it deserves some good type changes.  For
example, all these _shift are unsigned, and most are actually used as masks,
in form (1<<shift), instead of directly (except of erase_shift).

Thanks,

/mjt


WARNING: multiple messages have this Message-ID (diff)
From: Michael Tokarev <mjt@tls.msk.ru>
To: peter.crosthwaite@xilinx.com
Cc: Kevin Wolf <kwolf@redhat.com>,
	peter.maydell@linaro.org, qemu-trivial@nongnu.org,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
	edgar.iglesias@gmail.com
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH v1 1/5] block/nand: Factor out common code
Date: Wed, 19 Jun 2013 12:09:57 +0400	[thread overview]
Message-ID: <51C16755.9050700@msgid.tls.msk.ru> (raw)
In-Reply-To: <f65ba24ae67c04af46940c8cc67093894af97871.1371553360.git.peter.crosthwaite@xilinx.com>

18.06.2013 15:08, peter.crosthwaite@xilinx.com wrote:
> From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> 
> Most of this computation of s->iolen is the same for both the if and
> else paths here. Factor out the common parts outside the if.
> 
> Cc: qemu-trivial@nongnu.org
> 
> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> ---
> 
>  hw/block/nand.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/block/nand.c b/hw/block/nand.c
> index 087ca14..6309f93 100644
> --- a/hw/block/nand.c
> +++ b/hw/block/nand.c
> @@ -272,10 +272,10 @@ static void nand_command(NANDFlashState *s)
>              break;
>          offset = s->addr & ((1 << s->addr_shift) - 1);
>          s->blk_load(s, s->addr, offset);
> -        if (s->gnd)
> -            s->iolen = (1 << s->page_shift) - offset;
> -        else
> -            s->iolen = (1 << s->page_shift) + (1 << s->oob_shift) - offset;
> +        s->iolen = (1 << s->page_shift) - offset;
> +        if (!s->gnd) {
> +            s->iolen += 1 << s->oob_shift;
> +        }

Hm.  Can s->iolen become negative here?

addr_shift can be either less or greather than page_shift.  When addr_shift
is larger than page_shift (addr_shift=16, page_shift=11), offset may be up
to 65535, in which case s->iolen may be -63487, even without additional
oob_shift.

I dunno if this is a concern, just.. asking.

Besides, exactly the same expression is used in nand_getio() down this file,
maybe a common function is in order? :)

And looking at this file, I think it deserves some good type changes.  For
example, all these _shift are unsigned, and most are actually used as masks,
in form (1<<shift), instead of directly (except of erase_shift).

Thanks,

/mjt

  reply	other threads:[~2013-06-19  8:10 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-18 11:07 [Qemu-devel] [PATCH v1 0/5] Nand Cleanup peter.crosthwaite
2013-06-18 11:08 ` [Qemu-trivial] [PATCH v1 1/5] block/nand: Factor out common code peter.crosthwaite
2013-06-18 11:08   ` [Qemu-devel] " peter.crosthwaite
2013-06-19  8:09   ` Michael Tokarev [this message]
2013-06-19  8:09     ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2013-06-19  8:13     ` [Qemu-trivial] [Qemu-devel] " Peter Crosthwaite
2013-06-19  8:13       ` [Qemu-devel] [Qemu-trivial] " Peter Crosthwaite
2013-06-19  8:47       ` [Qemu-trivial] [Qemu-devel] " Michael Tokarev
2013-06-19  8:47         ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2013-07-31 23:49     ` [Qemu-trivial] [Qemu-devel] " Peter Crosthwaite
2013-07-31 23:49       ` [Qemu-devel] [Qemu-trivial] " Peter Crosthwaite
2013-06-19  8:54   ` Peter Maydell
2013-06-19  8:54     ` [Qemu-devel] " Peter Maydell
2013-06-18 11:08 ` [Qemu-trivial] [PATCH v1 2/5] block/nand: Formatting sweep peter.crosthwaite
2013-06-18 11:08   ` [Qemu-devel] " peter.crosthwaite
2013-06-19  7:53   ` [Qemu-trivial] " Michael Tokarev
2013-06-19  7:53     ` [Qemu-devel] " Michael Tokarev
2013-06-18 11:10 ` [Qemu-devel] [PATCH v1 3/5] block/nand: QOM casting sweep peter.crosthwaite
2013-06-19 10:52   ` Andreas Färber
2013-06-18 11:11 ` [Qemu-devel] [PATCH v1 4/5] block/nand: Convert Sysbus::init to Device::realize peter.crosthwaite
2013-06-19 10:56   ` Andreas Färber
2013-06-18 11:12 ` [Qemu-devel] [PATCH v1 5/5] nand: Don't inherit from Sysbus peter.crosthwaite
2013-06-19 11:06   ` Andreas Färber
2013-06-25 18:16 ` [Qemu-devel] [PATCH v1 0/5] Nand Cleanup Peter Maydell
2013-06-26  0:37   ` Peter Crosthwaite

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=51C16755.9050700@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=edgar.iglesias@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=stefanha@redhat.com \
    /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.