qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: zhanghailiang <zhang.zhanghailiang@huawei.com>,
	qemu-trivial@nongnu.org, Michael Tokarev <mjt@tls.msk.ru>
Cc: sw@weilnetz.de, armbru@redhat.com, qemu-devel@nongnu.org,
	afaerber@suse.de, peter.huangpeng@huawei.com
Subject: Re: [Qemu-devel] [PATCH v2] vt82c686: fix coverity warning about out-of-bounds write
Date: Tue, 09 Dec 2014 15:08:23 +0100	[thread overview]
Message-ID: <54870257.4070902@redhat.com> (raw)
In-Reply-To: <1418109359-2364-1-git-send-email-zhang.zhanghailiang@huawei.com>



On 09/12/2014 08:15, zhanghailiang wrote:
> Refactor superio_ioport_writeb to fix the out of bounds write warning.
> 
> In addition, fix two typos: s/chage/change/
> 
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> ---
>  - using bool instead of int for can_write as suggested by Stefan Weil
>  - fix two typos: s/chage/change
> ---
>  hw/isa/vt82c686.c | 41 +++++++++++++++++++----------------------
>  1 file changed, 19 insertions(+), 22 deletions(-)
> 
> diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
> index e0c235c..6c00f22 100644
> --- a/hw/isa/vt82c686.c
> +++ b/hw/isa/vt82c686.c
> @@ -50,13 +50,13 @@ typedef struct VT82C686BState {
>  static void superio_ioport_writeb(void *opaque, hwaddr addr, uint64_t data,
>                                    unsigned size)
>  {
> -    int can_write;
>      SuperIOConfig *superio_conf = opaque;
>  
>      DPRINTF("superio_ioport_writeb  address 0x%x  val 0x%x\n", addr, data);
>      if (addr == 0x3f0) {
>          superio_conf->index = data & 0xff;
>      } else {
> +        bool can_write = true;
>          /* 0x3f1 */
>          switch (superio_conf->index) {
>          case 0x00 ... 0xdf:
> @@ -68,30 +68,27 @@ static void superio_ioport_writeb(void *opaque, hwaddr addr, uint64_t data,
>          case 0xf7:
>          case 0xf9 ... 0xfb:
>          case 0xfd ... 0xff:
> -            can_write = 0;
> +            can_write = false;
>              break;
> -        default:
> -            can_write = 1;
> -
> -            if (can_write) {
> -                switch (superio_conf->index) {
> -                case 0xe7:
> -                    if ((data & 0xff) != 0xfe) {
> -                        DPRINTF("chage uart 1 base. unsupported yet\n");
> -                    }
> -                    break;
> -                case 0xe8:
> -                    if ((data & 0xff) != 0xbe) {
> -                        DPRINTF("chage uart 2 base. unsupported yet\n");
> -                    }
> -                    break;
> -
> -                default:
> -                    superio_conf->config[superio_conf->index] = data & 0xff;
> -                }
> +        case 0xe7:
> +            if ((data & 0xff) != 0xfe) {
> +                DPRINTF("change uart 1 base. unsupported yet\n");
> +                can_write = false;
> +            }
> +            break;
> +        case 0xe8:
> +            if ((data & 0xff) != 0xbe) {
> +                DPRINTF("change uart 2 base. unsupported yet\n");
> +                can_write = false;
>              }
> +            break;
> +        default:
> +            break;
> +
> +        }
> +        if (can_write == true) {

Michael, can you remove "== true" when applying this patch?

Thanks,

Paolo

> +            superio_conf->config[superio_conf->index] = data & 0xff;
>          }
> -        superio_conf->config[superio_conf->index] = data & 0xff;
>      }
>  }
>  
> 

  reply	other threads:[~2014-12-09 14:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-09  7:15 [Qemu-devel] [PATCH v2] vt82c686: fix coverity warning about out-of-bounds write zhanghailiang
2014-12-09 14:08 ` Paolo Bonzini [this message]
2014-12-10  8:57 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-12-10  9:14   ` Paolo Bonzini
2014-12-10  9:20   ` zhanghailiang
2014-12-10  9:53   ` Paolo Bonzini

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=54870257.4070902@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=afaerber@suse.de \
    --cc=armbru@redhat.com \
    --cc=mjt@tls.msk.ru \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=sw@weilnetz.de \
    --cc=zhang.zhanghailiang@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).