[libvirt PATCH 3/3] nodedev: handle null return from GetIOMMUGroupDev()

Jonathon Jongsma jjongsma at redhat.com
Tue Apr 13 20:49:33 UTC 2021


Coverity reported that this function can return NULL, so it should be
handled properly.

Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
---
 src/node_device/node_device_driver.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index 5f8995172d..2fcebd065b 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -1192,9 +1192,18 @@ nodeDeviceDestroy(virNodeDevicePtr device)
          * shouldn't try to remove the device. */
         g_autofree char *vfiogroup =
             virMediatedDeviceGetIOMMUGroupDev(def->caps->data.mdev.uuid);
-        VIR_AUTOCLOSE fd = open(vfiogroup, O_RDONLY);
+        VIR_AUTOCLOSE fd = -1;
         g_autofree char *errmsg = NULL;
 
+        if (!vfiogroup) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Unable to determine iommu group for '%s'"),
+                           def->name);
+            goto cleanup;
+        }
+
+        fd = open(vfiogroup, O_RDONLY);
+
         if (fd < 0 && errno == EBUSY) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Unable to destroy '%s': device in use"),
-- 
2.26.3




More information about the libvir-list mailing list