virhostdev: Use VIR_AUTOPTR more

There are couple of functions which get shorter after the
treatment.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2019-06-15 09:56:59 +02:00
parent df07ccc6e1
commit 27f866ba8a

View File

@ -1162,7 +1162,7 @@ virHostdevUpdateActiveUSBDevices(virHostdevManagerPtr mgr,
virObjectLock(mgr->activeUSBHostdevs);
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevSubsysUSBPtr usbsrc;
virUSBDevicePtr usb = NULL;
VIR_AUTOPTR(virUSBDevice) usb = NULL;
hostdev = hostdevs[i];
usbsrc = &hostdev->source.subsys.u.usb;
@ -1179,10 +1179,9 @@ virHostdevUpdateActiveUSBDevices(virHostdevManagerPtr mgr,
virUSBDeviceSetUsedBy(usb, drv_name, dom_name);
if (virUSBDeviceListAdd(mgr->activeUSBHostdevs, &usb) < 0) {
virUSBDeviceFree(usb);
if (virUSBDeviceListAdd(mgr->activeUSBHostdevs, &usb) < 0)
goto cleanup;
}
usb = NULL;
}
ret = 0;
cleanup:
@ -1198,7 +1197,7 @@ virHostdevUpdateActiveSCSIHostDevices(virHostdevManagerPtr mgr,
const char *dom_name)
{
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
virSCSIDevicePtr scsi = NULL;
VIR_AUTOPTR(virSCSIDevice) scsi = NULL;
virSCSIDevicePtr tmp = NULL;
if (!(scsi = virSCSIDeviceNew(NULL,
@ -1208,17 +1207,13 @@ virHostdevUpdateActiveSCSIHostDevices(virHostdevManagerPtr mgr,
return -1;
if ((tmp = virSCSIDeviceListFind(mgr->activeSCSIHostdevs, scsi))) {
if (virSCSIDeviceSetUsedBy(tmp, drv_name, dom_name) < 0) {
virSCSIDeviceFree(scsi);
if (virSCSIDeviceSetUsedBy(tmp, drv_name, dom_name) < 0)
return -1;
}
virSCSIDeviceFree(scsi);
} else {
if (virSCSIDeviceSetUsedBy(scsi, drv_name, dom_name) < 0 ||
virSCSIDeviceListAdd(mgr->activeSCSIHostdevs, scsi) < 0) {
virSCSIDeviceFree(scsi);
virSCSIDeviceListAdd(mgr->activeSCSIHostdevs, scsi) < 0)
return -1;
}
scsi = NULL;
}
return 0;
}
@ -1473,7 +1468,7 @@ virHostdevPrepareUSBDevices(virHostdevManagerPtr mgr,
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
bool required = true;
virUSBDevicePtr usb;
VIR_AUTOPTR(virUSBDevice) usb = NULL;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue;
@ -1488,10 +1483,9 @@ virHostdevPrepareUSBDevices(virHostdevManagerPtr mgr,
if (virHostdevFindUSBDevice(hostdev, required, &usb) < 0)
return -1;
if (usb && virUSBDeviceListAdd(list, &usb) < 0) {
virUSBDeviceFree(usb);
if (usb && virUSBDeviceListAdd(list, &usb) < 0)
return -1;
}
usb = NULL;
}
/* Mark devices in temporary list as used by @dom_name
@ -1519,7 +1513,7 @@ virHostdevPrepareSCSIHostDevices(virDomainHostdevDefPtr hostdev,
virSCSIDeviceListPtr list)
{
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
virSCSIDevicePtr scsi;
VIR_AUTOPTR(virSCSIDevice) scsi = NULL;
if (hostdev->managed) {
virReportError(VIR_ERR_XML_ERROR, "%s",
@ -1533,10 +1527,9 @@ virHostdevPrepareSCSIHostDevices(virDomainHostdevDefPtr hostdev,
hostdev->readonly, hostdev->shareable)))
return -1;
if (virSCSIDeviceListAdd(list, scsi) < 0) {
virSCSIDeviceFree(scsi);
if (virSCSIDeviceListAdd(list, scsi) < 0)
return -1;
}
scsi = NULL;
return 0;
}
@ -1747,7 +1740,7 @@ virHostdevPrepareMediatedDevices(virHostdevManagerPtr mgr,
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
virDomainHostdevSubsysMediatedDevPtr src = &hostdev->source.subsys.u.mdev;
virMediatedDevicePtr mdev;
VIR_AUTOPTR(virMediatedDevice) mdev = NULL;
if (!virHostdevIsMdevDevice(hostdev))
continue;
@ -1755,10 +1748,9 @@ virHostdevPrepareMediatedDevices(virHostdevManagerPtr mgr,
if (!(mdev = virMediatedDeviceNew(src->uuidstr, src->model)))
return -1;
if (virMediatedDeviceListAdd(list, &mdev) < 0) {
virMediatedDeviceFree(mdev);
if (virMediatedDeviceListAdd(list, &mdev) < 0)
return -1;
}
mdev = NULL;
}
/* Mark the devices in the list as used by @drv_name-@dom_name and copy the