]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_driver.c: validate 'driverName' earlier in qemuNodeDeviceDetachFlags()
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Sat, 30 Jan 2021 17:08:33 +0000 (14:08 -0300)
committerDaniel Henrique Barboza <danielhb413@gmail.com>
Wed, 17 Feb 2021 18:53:00 +0000 (15:53 -0300)
The validation of 'driverName' does not depend on any other state and can be
done right on the start of the function. We can fail earlier while avoiding
a cleanup jump.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/qemu/qemu_driver.c

index 9b949e23a81bb0835a66d6dc3f51cb0001294da8..888e2ec7748d89cad5e757eb7e93b29a5d92b320 100644 (file)
@@ -12010,6 +12010,25 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
 
     virCheckFlags(0, -1);
 
+    if (!driverName)
+        driverName = "vfio";
+
+    if (STREQ(driverName, "vfio") && !vfio) {
+        virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
+                       _("VFIO device assignment is currently not "
+                         "supported on this system"));
+         return -1;
+    } else if (STREQ(driverName, "kvm")) {
+        virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
+                       _("KVM device assignment is no longer "
+                         "supported on this system"));
+        return -1;
+    } else {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("unknown driver name '%s'"), driverName);
+        return -1;
+    }
+
     if (!(nodeconn = virGetConnectNodeDev()))
         goto cleanup;
 
@@ -12041,27 +12060,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
     if (!pci)
         goto cleanup;
 
-    if (!driverName)
-        driverName = "vfio";
-
-    if (STREQ(driverName, "vfio")) {
-        if (!vfio) {
-            virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-                           _("VFIO device assignment is currently not "
-                             "supported on this system"));
-            goto cleanup;
-        }
-        virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO);
-    } else if (STREQ(driverName, "kvm")) {
-        virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-                       _("KVM device assignment is no longer "
-                         "supported on this system"));
-        goto cleanup;
-    } else {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("unknown driver name '%s'"), driverName);
-        goto cleanup;
-    }
+    virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO);
 
     ret = virHostdevPCINodeDeviceDetach(hostdev_mgr, pci);
  cleanup: