[PATCH v2 06/10] libxl_driver.c: validate 'driverName' earlier in libxlNodeDeviceDetachFlags()

Daniel Henrique Barboza danielhb413 at gmail.com
Wed Feb 3 01:06:21 UTC 2021


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 at redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
---
 src/libxl/libxl_driver.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 316a6c6bf5..eadacdfb76 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -5791,6 +5791,12 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev,
 
     virCheckFlags(0, -1);
 
+    if (driverName && STRNEQ(driverName, "xen")) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("unsupported driver name '%s'"), driverName);
+        return -1;
+    }
+
     if (!(nodeconn = virGetConnectNodeDev()))
         goto cleanup;
 
@@ -5822,13 +5828,7 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev,
     if (!pci)
         goto cleanup;
 
-    if (!driverName || STREQ(driverName, "xen")) {
-        virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_XEN);
-    } else {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("unsupported driver name '%s'"), driverName);
-        goto cleanup;
-    }
+    virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_XEN);
 
     if (virHostdevPCINodeDeviceDetach(hostdev_mgr, pci) < 0)
         goto cleanup;
-- 
2.26.2




More information about the libvir-list mailing list