All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cao jin <caoj.fnst@cn.fujitsu.com>
To: qemu-devel@nongnu.org
Cc: stefano.stabellini@eu.citrix.com
Subject: [Qemu-devel] [PATCH v6 2/6] Xen: use qemu_strtoul instead of strtol
Date: Sun, 17 Jan 2016 20:13:11 +0800	[thread overview]
Message-ID: <1453032795-12690-3-git-send-email-caoj.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <1453032795-12690-1-git-send-email-caoj.fnst@cn.fujitsu.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 <caoj.fnst@cn.fujitsu.com>
---
 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

  parent reply	other threads:[~2016-01-17 12:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-17 12:13 [Qemu-devel] [PATCH v6 0/6] Xen PCI passthru: Convert to realize() Cao jin
2016-01-17 12:13 ` [Qemu-devel] [PATCH v6 1/6] Change xen_host_pci_sysfs_path() to return void Cao jin
2016-01-18 20:30   ` Eric Blake
2016-01-17 12:13 ` Cao jin [this message]
2016-01-20  0:09   ` [Qemu-devel] [PATCH v6 2/6] Xen: use qemu_strtoul instead of strtol Eric Blake
2016-01-17 12:13 ` [Qemu-devel] [PATCH v6 3/6] Add Error **errp for xen_host_pci_device_get() Cao jin
2016-01-21 16:23   ` Eric Blake
2016-01-17 12:13 ` [Qemu-devel] [PATCH v6 4/6] Add Error **errp for xen_pt_setup_vga() Cao jin
2016-01-17 12:13 ` [Qemu-devel] [PATCH v6 5/6] Add Error **errp for xen_pt_config_init() Cao jin
2016-01-17 12:13 ` [Qemu-devel] [PATCH v6 6/6] Xen PCI passthru: convert to realize() Cao jin
2016-01-19  1:38 ` [Qemu-devel] [PATCH v6 0/6] Xen PCI passthru: Convert " Cao jin
2016-01-19  7:22   ` Markus Armbruster
2016-01-21 13:26 ` Cao jin
2016-01-21 15:41   ` Stefano Stabellini
2016-01-21 16:24     ` Eric Blake
2016-01-21 16:39       ` Stefano Stabellini
2016-01-22  6:00     ` Cao jin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453032795-12690-3-git-send-email-caoj.fnst@cn.fujitsu.com \
    --to=caoj.fnst@cn.fujitsu.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefano.stabellini@eu.citrix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.