summaryrefslogtreecommitdiffstats
path: root/hw
diff options
context:
space:
mode:
authorCao jin <caoj.fnst@cn.fujitsu.com>2016-01-17 20:13:11 +0800
committerTimothy Pearson <tpearson@raptorengineering.com>2019-11-29 19:29:54 -0600
commit6b1a25766f12c391e0d96f2df1ecd5f9df9ed833 (patch)
treec4d795280e28e00116aab26f845e70a0a44c7162 /hw
parent4bd76cae9e58bf1a02bada72933854b4f8a95c1e (diff)
downloadhqemu-6b1a25766f12c391e0d96f2df1ecd5f9df9ed833.zip
hqemu-6b1a25766f12c391e0d96f2df1ecd5f9df9ed833.tar.gz
Xen: use qemu_strtoul instead of strtol
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 <caoj.fnst@cn.fujitsu.com> Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/xen/xen-host-pci-device.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/hw/xen/xen-host-pci-device.c b/hw/xen/xen-host-pci-device.c
index 9c342e7..83da9c4 100644
--- a/hw/xen/xen-host-pci-device.c
+++ b/hw/xen/xen-host-pci-device.c
@@ -141,7 +141,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;
xen_host_pci_sysfs_path(d, name, path, sizeof(path));
@@ -158,13 +158,9 @@ 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) {
+ assert(value <= UINT_MAX);
*pvalue = value;
}
out:
OpenPOWER on IntegriCloud