From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43031) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zf5Oy-0006Jx-W2 for qemu-devel@nongnu.org; Thu, 24 Sep 2015 08:13:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zf5Ox-0000Jq-TV for qemu-devel@nongnu.org; Thu, 24 Sep 2015 08:13:28 -0400 Received: from mail-ob0-x22a.google.com ([2607:f8b0:4003:c01::22a]:33368) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zf5Ox-0000JU-Q1 for qemu-devel@nongnu.org; Thu, 24 Sep 2015 08:13:27 -0400 Received: by obbbh8 with SMTP id bh8so56227287obb.0 for ; Thu, 24 Sep 2015 05:13:27 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <1443094669-4144-43-git-send-email-marcandre.lureau@redhat.com> References: <1443094669-4144-1-git-send-email-marcandre.lureau@redhat.com> <1443094669-4144-43-git-send-email-marcandre.lureau@redhat.com> Date: Thu, 24 Sep 2015 14:13:27 +0200 Message-ID: From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v4 42/47] ivshmem: use strtosz() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU Cc: Andrew Jones , Claudio Fontana , Stefan Hajnoczi , =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= , Paolo Bonzini , cam On Thu, Sep 24, 2015 at 1:37 PM, wrote: > From: Marc-Andr=C3=A9 Lureau > > Use the common qemu utility function to parse the memory size. > > Signed-off-by: Marc-Andr=C3=A9 Lureau > --- > hw/misc/ivshmem.c | 36 +++++------------------------------- > 1 file changed, 5 insertions(+), 31 deletions(-) > > diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c > index 273db36..0ee61d5 100644 > --- a/hw/misc/ivshmem.c > +++ b/hw/misc/ivshmem.c > @@ -646,33 +646,6 @@ static void ivshmem_reset(DeviceState *d) > ivshmem_use_msix(s); > } > > -static uint64_t ivshmem_get_size(IVShmemState * s, Error **errp) { > - > - uint64_t value; > - char *ptr; > - > - value =3D strtoull(s->sizearg, &ptr, 10); > - switch (*ptr) { > - case 0: case 'M': case 'm': > - value <<=3D 20; > - break; > - case 'G': case 'g': > - value <<=3D 30; > - break; > - default: > - error_setg(errp, "invalid ram size: %s", s->sizearg); > - return 0; > - } > - > - /* BARs must be a power of 2 */ > - if (!is_power_of_2(value)) { > - error_setg(errp, "size must be power of 2"); > - return 0; > - } > - > - return value; > -} > - > static int ivshmem_setup_msi(IVShmemState * s) > { > if (msix_init_exclusive_bar(PCI_DEVICE(s), s->vectors, 1)) { > @@ -700,16 +673,17 @@ static void pci_ivshmem_realize(PCIDevice *dev, Err= or **errp) > uint8_t *pci_conf; > uint8_t attr =3D PCI_BASE_ADDRESS_SPACE_MEMORY | > PCI_BASE_ADDRESS_MEM_PREFETCH; > - Error *local_err =3D NULL; > > if (s->sizearg =3D=3D NULL) { > s->ivshmem_size =3D 4 << 20; /* 4 MB default */ > } else { > - s->ivshmem_size =3D ivshmem_get_size(s, &local_err); > - if (local_err) { > - error_propagate(errp, local_err); > + char *end; > + int64_t size =3D strtosz(s->sizearg, &end); > + if (size < 0 || *end !=3D '\0') { > + error_setg(errp, "Invalid size %s", s->sizearg); > return; > } > + s->ivshmem_size =3D size; > } > > fifo8_create(&s->incoming_fifo, sizeof(long)); > -- > 2.4.3 > scrap this one, it doesn't check the power of 2, and I wonder if accepting values lower than megabyte is acceptable --=20 Marc-Andr=C3=A9 Lureau