From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zj3D2-0001dh-L4 for qemu-devel@nongnu.org; Mon, 05 Oct 2015 06:41:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zj3Cz-0006wT-Bh for qemu-devel@nongnu.org; Mon, 05 Oct 2015 06:41:32 -0400 Received: from lhrrgout.huawei.com ([194.213.3.17]:9933) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zj3Cy-0006wO-N4 for qemu-devel@nongnu.org; Mon, 05 Oct 2015 06:41:29 -0400 References: <1443812991-17356-1-git-send-email-marcandre.lureau@redhat.com> <1443812991-17356-44-git-send-email-marcandre.lureau@redhat.com> From: Claudio Fontana Message-ID: <561253CE.8090306@huawei.com> Date: Mon, 5 Oct 2015 12:41:18 +0200 MIME-Version: 1.0 In-Reply-To: <1443812991-17356-44-git-send-email-marcandre.lureau@redhat.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v5 43/48] ivshmem: use qemu_strtosz() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org Cc: pbonzini@redhat.com, drjones@redhat.com, cam@cs.ualberta.ca, stefanha@redhat.com On 02.10.2015 21:09, marcandre.lureau@redhat.com wrote: > From: Marc-André Lureau > > Use the common qemu utility function to parse the memory size. > > Signed-off-by: Marc-André 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 b873c23..707e82c 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 = strtoull(s->sizearg, &ptr, 10); > - switch (*ptr) { > - case 0: case 'M': case 'm': > - value <<= 20; > - break; > - case 'G': case 'g': > - value <<= 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, Error **errp) > uint8_t *pci_conf; > uint8_t attr = PCI_BASE_ADDRESS_SPACE_MEMORY | > PCI_BASE_ADDRESS_MEM_PREFETCH; > - Error *local_err = NULL; > > if (s->sizearg == NULL) { > s->ivshmem_size = 4 << 20; /* 4 MB default */ > } else { > - s->ivshmem_size = ivshmem_get_size(s, &local_err); > - if (local_err) { > - error_propagate(errp, local_err); > + char *end; > + int64_t size = qemu_strtosz(s->sizearg, &end); > + if (size < 0 || *end != '\0' || !is_power_of_2(size)) { > + error_setg(errp, "Invalid size %s", s->sizearg); > return; > } > + s->ivshmem_size = size; > } > > fifo8_create(&s->incoming_fifo, sizeof(long)); > Reviewed-by: Claudio Fontana