Skip to contentSkip to conversation

tests/libqos: Check for valid dev pointer when looking for PCI devices

PATCH Applied Thomas Huth 2 participants 2 messages Feb 27, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/libqos: Check for valid dev pointer when looking for PCI devices

dev could be NULL if the PCI device can not be found due to some reasons, so we must not dereference the pointer in this case.

---
 tests/libqos/virtio-pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/libqos/virtio-pci.c +3 -1
index 7ac15c0..550dede 100644
@@ -315,7 +315,9 @@ QVirtioPCIDevice *qvirtio_pci_device_find(QPCIBus *bus, uint16_t device_type)
     qvirtio_pci_foreach(bus, device_type, false, 0,
                         qvirtio_pci_assign_device, &dev);
 
-    dev->vdev.bus = &qvirtio_pci;
+    if (dev) {
+        dev->vdev.bus = &qvirtio_pci;
+    }
 
     return dev;
 }
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 7 lines · Thomas Huth

dev could be NULL if the PCI device can not be found due to some reasons, so we must not dereference the pointer in this case.

---
 tests/libqos/virtio-pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

There is no maintainer for tests/libqos/virtio-pci.c in MAINTAINERS so I'll take this patch.

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan