From: Michal Privoznik Date: Sat, 15 Jun 2019 06:25:33 +0000 (+0200) Subject: virHostdevGetPCIHostDeviceList: Add @pci a bit later X-Git-Tag: v5.5.0-rc1~138 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7cf2963017d9b730d5762094750a0676599a09ab;p=thirdparty%2Flibvirt.git virHostdevGetPCIHostDeviceList: Add @pci a bit later This function is a good candidate for VIR_AUTOPTR() conversion. But this conversion will be easier if we only add @pci device onto @pcidevs list after it was all set up. This is no functional change. Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index fe176f35e4..9c63d0aebd 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -240,11 +240,6 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs) virObjectUnref(pcidevs); return NULL; } - if (virPCIDeviceListAdd(pcidevs, pci) < 0) { - virPCIDeviceFree(pci); - virObjectUnref(pcidevs); - return NULL; - } virPCIDeviceSetManaged(pci, hostdev->managed); @@ -254,6 +249,12 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs) virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_XEN); else virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_KVM); + + if (virPCIDeviceListAdd(pcidevs, pci) < 0) { + virPCIDeviceFree(pci); + virObjectUnref(pcidevs); + return NULL; + } } return pcidevs;