[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 2/6] Xen: use qemu_strtoul instead of strtol
From: |
Cao jin |
Subject: |
[Qemu-devel] [PATCH v6 2/6] Xen: use qemu_strtoul instead of strtol |
Date: |
Sun, 17 Jan 2016 20:13:11 +0800 |
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 <address@hidden>
---
hw/xen/xen-host-pci-device.c | 12 ++++--------
1 file 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:
--
2.1.0
- [Qemu-devel] [PATCH v6 0/6] Xen PCI passthru: Convert to realize(), Cao jin, 2016/01/17
- [Qemu-devel] [PATCH v6 2/6] Xen: use qemu_strtoul instead of strtol,
Cao jin <=
- [Qemu-devel] [PATCH v6 1/6] Change xen_host_pci_sysfs_path() to return void, Cao jin, 2016/01/17
- [Qemu-devel] [PATCH v6 4/6] Add Error **errp for xen_pt_setup_vga(), Cao jin, 2016/01/17
- [Qemu-devel] [PATCH v6 6/6] Xen PCI passthru: convert to realize(), Cao jin, 2016/01/17
- [Qemu-devel] [PATCH v6 5/6] Add Error **errp for xen_pt_config_init(), Cao jin, 2016/01/17
- [Qemu-devel] [PATCH v6 3/6] Add Error **errp for xen_host_pci_device_get(), Cao jin, 2016/01/17
- Re: [Qemu-devel] [PATCH v6 0/6] Xen PCI passthru: Convert to realize(), Cao jin, 2016/01/18