From: "Michael S. Tsirkin" <m...@redhat.com> This reverts commit bccb20c49df1bd683248a366021973901c11982f as it introduced a regression blocking bus addresses > 0x1f or higher. Legal bus numbers go up to 0xff.
Fixes: bccb20c49df ("Use qemu_strtoul() in set_pci_host_devaddr()") Reported-by: Klaus Herman <kher...@inbox.lv> Reported-by: Geoffrey McRae <ge...@hostfission.com> Signed-off-by: Michael S. Tsirkin <m...@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <phi...@redhat.com> Cc: "Philippe Mathieu-Daudé" <phi...@redhat.com> Message-Id: <20201120130409.956956-1-...@redhat.com> Signed-off-by: Eduardo Habkost <ehabk...@redhat.com> --- hw/core/qdev-properties-system.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index b81a4e8d14..9d80a07d26 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -858,7 +858,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; - const char *e; + char *e; unsigned long val; unsigned long dom = 0, bus = 0; unsigned int slot = 0, func = 0; @@ -873,23 +873,23 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name, } p = str; - if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0xffff || e == p) { - goto inval; - } - if (*e != ':') { + val = strtoul(p, &e, 16); + if (e == p || *e != ':') { goto inval; } bus = val; - p = (char *)e + 1; - if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e == p) { + p = e + 1; + val = strtoul(p, &e, 16); + if (e == p) { goto inval; } if (*e == ':') { dom = bus; bus = val; - p = (char *)e + 1; - if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e == p) { + p = e + 1; + val = strtoul(p, &e, 16); + if (e == p) { goto inval; } } @@ -898,13 +898,14 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name, if (*e != '.') { goto inval; } - p = (char *)e + 1; - if (qemu_strtoul(p, &e, 10, &val) < 0 || val > 7 || e == p) { + p = e + 1; + val = strtoul(p, &e, 10); + if (e == p) { goto inval; } func = val; - if (bus > 0xff) { + if (dom > 0xffff || bus > 0xff || slot > 0x1f || func > 7) { goto inval; } -- 2.28.0