From: Daniel Henrique Barboza Date: Sat, 30 Jan 2021 16:59:06 +0000 (-0300) Subject: libxl_driver.c: validate 'driverName' earlier in libxlNodeDeviceDetachFlags() X-Git-Tag: v7.1.0-rc1~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04871c511e9bb2c2b6ff8561a07e1ad9c3082d5b;p=thirdparty%2Flibvirt.git libxl_driver.c: validate 'driverName' earlier in libxlNodeDeviceDetachFlags() 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 Signed-off-by: Daniel Henrique Barboza --- diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 172fe28436..b44715eee1 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5784,6 +5784,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; @@ -5815,13 +5821,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;