diff mbox series

[v3,03/11] hw/core/qdev-properties: Use qemu_strtoul() in set_pci_host_devaddr()

Message ID 20200930164949.1425294-4-philmd@redhat.com
State New
Headers show
Series user-mode: Prune build dependencies (part 3) | expand

Commit Message

Philippe Mathieu-Daudé Sept. 30, 2020, 4:49 p.m. UTC
Replace strtoul() by qemu_strtoul() so checkpatch.pl won't complain
if we move this code later.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/core/qdev-properties.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 080ba319a1..a1190a5db9 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -951,7 +951,7 @@  static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
     Property *prop = opaque;
     PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop);
     char *str, *p;
-    char *e;
+    const char *e;
     unsigned long val;
     unsigned long dom = 0, bus = 0;
     unsigned int slot = 0, func = 0;
@@ -966,23 +966,23 @@  static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
     }
 
     p = str;
-    val = strtoul(p, &e, 16);
-    if (e == p || *e != ':') {
+    if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0xffff || e == p) {
+        goto inval;
+    }
+    if (*e != ':') {
         goto inval;
     }
     bus = val;
 
-    p = e + 1;
-    val = strtoul(p, &e, 16);
-    if (e == p) {
+    p = (char *)e + 1;
+    if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e == p) {
         goto inval;
     }
     if (*e == ':') {
         dom = bus;
         bus = val;
-        p = e + 1;
-        val = strtoul(p, &e, 16);
-        if (e == p) {
+        p = (char *)e + 1;
+        if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e == p) {
             goto inval;
         }
     }
@@ -991,14 +991,13 @@  static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
     if (*e != '.') {
         goto inval;
     }
-    p = e + 1;
-    val = strtoul(p, &e, 10);
-    if (e == p) {
+    p = (char *)e + 1;
+    if (qemu_strtoul(p, &e, 10, &val) < 0 || val > 7 || e == p) {
         goto inval;
     }
     func = val;
 
-    if (dom > 0xffff || bus > 0xff || slot > 0x1f || func > 7) {
+    if (bus > 0xff) {
         goto inval;
     }