All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: peter.maydell@linaro.org
Cc: Cao jin <caoj.fnst@cn.fujitsu.com>,
	xen-devel@lists.xensource.com, qemu-devel@nongnu.org,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [Qemu-devel] [PULL 07/11] Xen: use qemu_strtoul instead of strtol
Date: Thu, 21 Jan 2016 17:01:26 +0000	[thread overview]
Message-ID: <1453395690-32660-7-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1601211649260.13552@kaball.uk.xensource.com>

From: Cao jin <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>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Reviewed-by: Eric Blake <eblake@redhat.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:
-- 
1.7.10.4

WARNING: multiple messages have this Message-ID (diff)
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: peter.maydell@linaro.org
Cc: Cao jin <caoj.fnst@cn.fujitsu.com>,
	xen-devel@lists.xensource.com, qemu-devel@nongnu.org,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PULL 07/11] Xen: use qemu_strtoul instead of strtol
Date: Thu, 21 Jan 2016 17:01:26 +0000	[thread overview]
Message-ID: <1453395690-32660-7-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1601211649260.13552@kaball.uk.xensource.com>

From: Cao jin <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>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Reviewed-by: Eric Blake <eblake@redhat.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:
-- 
1.7.10.4

  parent reply	other threads:[~2016-01-21 17:02 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-21 17:01 [Qemu-devel] [PULL 0/11] xen-20160121 Stefano Stabellini
2016-01-21 17:01 ` Stefano Stabellini
2016-01-21 17:01 ` [Qemu-devel] [PULL 01/11] MAINTAINERS: update Xen files Stefano Stabellini
2016-01-21 17:01   ` Stefano Stabellini
2016-01-21 17:01 ` [Qemu-devel] [PULL 02/11] xenfb.c: avoid expensive loops when prod <= out_cons Stefano Stabellini
2016-01-21 17:01   ` Stefano Stabellini
2016-01-21 17:01 ` [Qemu-devel] [PULL 03/11] xen-hvm: Clean up xen_hvm_init() error handling Stefano Stabellini
2016-01-21 17:01   ` Stefano Stabellini
2016-01-21 17:01 ` [Qemu-devel] [PULL 04/11] xen-hvm: Clean up xen_ram_alloc() " Stefano Stabellini
2016-01-21 17:01   ` Stefano Stabellini
2016-01-21 17:01 ` [Qemu-devel] [PULL 05/11] xen-pvdevice: convert to realize() Stefano Stabellini
2016-01-21 17:01   ` Stefano Stabellini
2016-01-21 17:01 ` [Qemu-devel] [PULL 06/11] Change xen_host_pci_sysfs_path() to return void Stefano Stabellini
2016-01-21 17:01   ` Stefano Stabellini
2016-01-21 17:01 ` Stefano Stabellini [this message]
2016-01-21 17:01   ` [PULL 07/11] Xen: use qemu_strtoul instead of strtol Stefano Stabellini
2016-01-21 17:01 ` [Qemu-devel] [PULL 08/11] Add Error **errp for xen_host_pci_device_get() Stefano Stabellini
2016-01-21 17:01   ` Stefano Stabellini
2016-01-21 17:01 ` [Qemu-devel] [PULL 09/11] Add Error **errp for xen_pt_setup_vga() Stefano Stabellini
2016-01-21 17:01   ` Stefano Stabellini
2016-01-21 17:01 ` [Qemu-devel] [PULL 10/11] Add Error **errp for xen_pt_config_init() Stefano Stabellini
2016-01-21 17:01   ` Stefano Stabellini
2016-01-22 11:21   ` [Qemu-devel] " Paolo Bonzini
2016-01-22 11:21     ` Paolo Bonzini
2016-01-23 12:23     ` [Qemu-devel] " Cao jin
2016-01-23 12:23       ` Cao jin
2016-01-25 10:53       ` [Qemu-devel] " Stefano Stabellini
2016-01-25 10:53         ` Stefano Stabellini
2016-01-21 17:01 ` [Qemu-devel] [PULL 11/11] Xen PCI passthru: convert to realize() Stefano Stabellini
2016-01-21 17:01   ` Stefano Stabellini
2016-01-21 17:45 ` [Qemu-devel] [PULL 0/11] xen-20160121 Peter Maydell
2016-01-21 17:45   ` Peter Maydell

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=1453395690-32660-7-git-send-email-stefano.stabellini@eu.citrix.com \
    --to=stefano.stabellini@eu.citrix.com \
    --cc=caoj.fnst@cn.fujitsu.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=xen-devel@lists.xensource.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.