Revert "hw/core/qdev-properties: Use qemu_strtoul() in set_pci_host_devaddr()"

This reverts commit bccb20c49d as it
introduced a regression blocking bus addresses > 0x1f or higher.
Legal bus numbers go up to 0xff.

Fixes: bccb20c49d ("Use qemu_strtoul() in set_pci_host_devaddr()")
Reported-by: Klaus Herman <kherman@inbox.lv>
Reported-by: Geoffrey McRae <geoff@hostfission.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Message-Id: <20201120130409.956956-1-mst@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
Michael S. Tsirkin 2020-11-20 08:04:54 -05:00 committed by Eduardo Habkost
parent d536d9578e
commit 28afbc1f11

View file

@ -858,7 +858,7 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
Property *prop = opaque; Property *prop = opaque;
PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop); PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop);
char *str, *p; char *str, *p;
const char *e; char *e;
unsigned long val; unsigned long val;
unsigned long dom = 0, bus = 0; unsigned long dom = 0, bus = 0;
unsigned int slot = 0, func = 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; p = str;
if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0xffff || e == p) { val = strtoul(p, &e, 16);
goto inval; if (e == p || *e != ':') {
}
if (*e != ':') {
goto inval; goto inval;
} }
bus = val; bus = val;
p = (char *)e + 1; p = e + 1;
if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e == p) { val = strtoul(p, &e, 16);
if (e == p) {
goto inval; goto inval;
} }
if (*e == ':') { if (*e == ':') {
dom = bus; dom = bus;
bus = val; bus = val;
p = (char *)e + 1; p = e + 1;
if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e == p) { val = strtoul(p, &e, 16);
if (e == p) {
goto inval; goto inval;
} }
} }
@ -898,13 +898,14 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
if (*e != '.') { if (*e != '.') {
goto inval; goto inval;
} }
p = (char *)e + 1; p = e + 1;
if (qemu_strtoul(p, &e, 10, &val) < 0 || val > 7 || e == p) { val = strtoul(p, &e, 10);
if (e == p) {
goto inval; goto inval;
} }
func = val; func = val;
if (bus > 0xff) { if (dom > 0xffff || bus > 0xff || slot > 0x1f || func > 7) {
goto inval; goto inval;
} }