From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58221) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZgwG1-0004Jr-La for qemu-devel@nongnu.org; Tue, 29 Sep 2015 10:51:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZgwFv-0004l2-JM for qemu-devel@nongnu.org; Tue, 29 Sep 2015 10:51:53 -0400 Received: from mx3-phx2.redhat.com ([209.132.183.24]:33886) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZgwFv-0004kk-C0 for qemu-devel@nongnu.org; Tue, 29 Sep 2015 10:51:47 -0400 Date: Tue, 29 Sep 2015 10:51:31 -0400 (EDT) From: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Message-ID: <1106477454.19882766.1443538291628.JavaMail.zimbra@redhat.com> In-Reply-To: <560AA16F.50507@huawei.com> References: <1443094669-4144-1-git-send-email-marcandre.lureau@redhat.com> <1443094669-4144-43-git-send-email-marcandre.lureau@redhat.com> <560AA16F.50507@huawei.com> MIME-Version: 1.0 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: Claudio Fontana Cc: drjones@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, pbonzini@redhat.com, marcandre lureau , cam@cs.ualberta.ca ----- Original Message ----- > On 24.09.2015 13:37, marcandre.lureau@redhat.com wrote: > > From: Marc-Andr=C3=A9 Lureau > >=20 > > Use the common qemu utility function to parse the memory size. > >=20 > > Signed-off-by: Marc-Andr=C3=A9 Lureau > > --- > > hw/misc/ivshmem.c | 36 +++++------------------------------- > > 1 file changed, 5 insertions(+), 31 deletions(-) > >=20 > > 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); > > } > > =20 > > -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, E= rror > > **errp) > > uint8_t *pci_conf; > > uint8_t attr =3D PCI_BASE_ADDRESS_SPACE_MEMORY | > > PCI_BASE_ADDRESS_MEM_PREFETCH; > > - Error *local_err =3D NULL; > > =20 > > 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') { >=20 > If there is additional validation that you need to do (in light of your > comments to this patch), > it could be done here instead of failing later. It will duplicate the check done by pci bar code, but I agree it could be d= one here too. I'll add it. >=20 > > + error_setg(errp, "Invalid size %s", s->sizearg); > > return; > > } > > + s->ivshmem_size =3D size; > > } > > =20 > > fifo8_create(&s->incoming_fifo, sizeof(long)); > >=20 >=20 >=20 >=20