From patchwork Thu Sep 24 11:37:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 522259 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 152DF140281 for ; Thu, 24 Sep 2015 21:50:16 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=pdngQN0k; dkim-atps=neutral Received: from localhost ([::1]:58087 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zf52S-0002Y2-Tw for incoming@patchwork.ozlabs.org; Thu, 24 Sep 2015 07:50:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59911) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zf4sP-0001Nw-4x for qemu-devel@nongnu.org; Thu, 24 Sep 2015 07:39:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zf4sO-0007IS-89 for qemu-devel@nongnu.org; Thu, 24 Sep 2015 07:39:49 -0400 Received: from mail-qk0-x230.google.com ([2607:f8b0:400d:c09::230]:35824) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zf4sO-0007IN-4e for qemu-devel@nongnu.org; Thu, 24 Sep 2015 07:39:48 -0400 Received: by qkap81 with SMTP id p81so28335307qka.2 for ; Thu, 24 Sep 2015 04:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=wgtL+AXTV5YOp1W+zJGgiuZzI+L8W8jprIjXVhWkYJs=; b=pdngQN0kyvp7gTYj+R0UcaZvimIKB+gwZxY3Tqw6sfbP5Rxv+077diECpCGBMsTzd0 cGL6Bw74dvnUTRnLlPhwZwPxA5dfOK7fgHADQfQESZVny9YVSnO96FtTBefIeUEy1UM+ 9PX9xnBQEN0BN9GNdsi8w12Fs+/uQPRLvArwupcFYUcxw5tfnGSOxFWObOmev08aMRY9 9gpPeLyInRtpFwc5TkcFDhRQFHYIEJLgGsQeGLSMPZbahv7GCrqfCzT4DCwgv7xXIWuR X/zb3igwVpJPgCDcReUG/42MbeknVybn/ngFO15YHB5y+CnN1uAIz7l8Gkk98OIGhI1K NkQA== X-Received: by 10.55.198.201 with SMTP id s70mr42199684qkl.42.1443094787916; Thu, 24 Sep 2015 04:39:47 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id t69sm4322927qki.11.2015.09.24.04.39.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Sep 2015 04:39:47 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Thu, 24 Sep 2015 13:37:44 +0200 Message-Id: <1443094669-4144-43-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1443094669-4144-1-git-send-email-marcandre.lureau@redhat.com> References: <1443094669-4144-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c09::230 Cc: drjones@redhat.com, claudio.fontana@huawei.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, cam@cs.ualberta.ca Subject: [Qemu-devel] [PATCH v4 42/47] ivshmem: use strtosz() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 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 = 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 = strtosz(s->sizearg, &end); + if (size < 0 || *end != '\0') { + error_setg(errp, "Invalid size %s", s->sizearg); return; } + s->ivshmem_size = size; } fifo8_create(&s->incoming_fifo, sizeof(long));