diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2015-06-30 00:06:03 +0200 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2015-10-26 10:19:53 +0100 |
commit | 2c04752cc8e37b15be4643570b49abb3128a8a46 (patch) | |
tree | 7eb59dc0e9883e09c02edea1e068a1bad7c1bd89 | |
parent | f689d2811a36894618087e1e2cc3ade78e758e94 (diff) |
ivshmem: use qemu_strtosz()
Use the common qemu utility function to parse the memory size.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Claudio Fontana <claudio.fontana@huawei.com>
-rw-r--r-- | hw/misc/ivshmem.c | 36 |
1 files changed, 5 insertions, 31 deletions
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 75d7f89afb..1f381bdf23 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -645,33 +645,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)) { @@ -699,16 +672,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)); |