Received: from eggs.gnu.org ([2001:4830:134:3::10]:49472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJKrK-0003Lz-6G for qemu-devel@nongnu.org; Wed, 13 Jan 2016 07:49:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJKrG-00078u-TL for qemu-devel@nongnu.org; Wed, 13 Jan 2016 07:49:06 -0500 Received: from [59.151.112.132] (port=42430 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJKrG-000777-IA for qemu-devel@nongnu.org; Wed, 13 Jan 2016 07:49:02 -0500 From: Cao jin Date: Wed, 13 Jan 2016 20:51:43 +0800 Message-ID: <1452689507-8188-2-git-send-email-caoj.fnst@cn.fujitsu.com> In-Reply-To: <1452689507-8188-1-git-send-email-caoj.fnst@cn.fujitsu.com> References: <1452689507-8188-1-git-send-email-caoj.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v5 1/5] Xen: use qemu_strtoul instead of strtol List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: stefano.stabellini@eu.citrix.com No need to roll our own (with slightly incorrect handling of errno), when we can use the common version. Change signed parsing to unsigned, because what it read are values in PCI config space, which are non-negative. Signed-off-by: Cao jin --- hw/xen/xen-host-pci-device.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/hw/xen/xen-host-pci-device.c b/hw/xen/xen-host-pci-device.c index 7d8a023..351b61a 100644 --- a/hw/xen/xen-host-pci-device.c +++ b/hw/xen/xen-host-pci-device.c @@ -148,7 +148,7 @@ static int xen_host_pci_get_value(XenHostPCIDevice *d, const char *name, char buf[XEN_HOST_PCI_GET_VALUE_BUFFER_SIZE]; int fd, rc; unsigned long value; - char *endptr; + const char *endptr; rc = xen_host_pci_sysfs_path(d, name, path, sizeof (path)); if (rc) { @@ -167,13 +167,8 @@ static int xen_host_pci_get_value(XenHostPCIDevice *d, const char *name, } } while (rc < 0); buf[rc] = 0; - value = strtol(buf, &endptr, base); - if (endptr == buf || *endptr != '\n') { - rc = -1; - } else if ((value == LONG_MIN || value == LONG_MAX) && errno == ERANGE) { - rc = -errno; - } else { - rc = 0; + rc = qemu_strtoul(buf, &endptr, base, &value); + if (!rc) { *pvalue = value; } out: -- 2.1.0