summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2016-11-15 19:02:08 +0000
committerStefan Hajnoczi <stefanha@redhat.com>2016-11-15 19:02:09 +0000
commit60c5a47a16aa227155877b1436b4467a106587d6 (patch)
tree69182f85a6441c016be005394f9488111fde2f3c
parent82e6e5ef0ec0e55e2be215153219f0ca8b3bee84 (diff)
parent00b8702581f312aa46f797a8b3153d9b2892d967 (diff)
downloadqemu-60c5a47a16aa227155877b1436b4467a106587d6.tar.gz
Merge remote-tracking branch 'ehabkost/tags/machine-pull-request' into staging
qdev: Fix assert in PCI address property when used by vfio-pci # gpg: Signature made Tue 15 Nov 2016 06:27:18 PM GMT # gpg: using RSA key 0x2807936F984DC5A6 # gpg: Good signature from "Eduardo Habkost <ehabkost@redhat.com>" # Primary key fingerprint: 5A32 2FD5 ABC4 D3DB ACCF D1AA 2807 936F 984D C5A6 * ehabkost/tags/machine-pull-request: qdev: Fix assert in PCI address property when used by vfio-pci Message-id: 1479234540-3192-1-git-send-email-ehabkost@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r--hw/core/qdev-properties.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 311af6da76..2a82768067 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -705,13 +705,19 @@ static void get_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop);
- char buffer[] = "xxxx:xx:xx.x";
+ char buffer[] = "ffff:ff:ff.f";
char *p = buffer;
int rc = 0;
- rc = snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%d",
- addr->domain, addr->bus, addr->slot, addr->function);
- assert(rc == sizeof(buffer) - 1);
+ /*
+ * Catch "invalid" device reference from vfio-pci and allow the
+ * default buffer representing the non-existant device to be used.
+ */
+ if (~addr->domain || ~addr->bus || ~addr->slot || ~addr->function) {
+ rc = snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%0d",
+ addr->domain, addr->bus, addr->slot, addr->function);
+ assert(rc == sizeof(buffer) - 1);
+ }
visit_type_str(v, name, &p, errp);
}