mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
security_selinux.c: use g_auto* in set/restore hostdev subsys functions
Use g_auto* cleanup to avoid free() calls. Reviewed-by: Laine Stump <laine@redhat.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
b0264e9404
commit
e49319534e
@ -2087,7 +2087,7 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
|
||||
|
||||
switch ((virDomainHostdevSubsysType)dev->source.subsys.type) {
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
|
||||
virUSBDevicePtr usb;
|
||||
g_autoptr(virUSBDevice) usb = NULL;
|
||||
|
||||
if (dev->missing)
|
||||
return 0;
|
||||
@ -2099,39 +2099,34 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
|
||||
return -1;
|
||||
|
||||
ret = virUSBDeviceFileIterate(usb, virSecuritySELinuxSetUSBLabel, &data);
|
||||
virUSBDeviceFree(usb);
|
||||
break;
|
||||
}
|
||||
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
|
||||
virPCIDevicePtr pci =
|
||||
virPCIDeviceNew(&pcisrc->addr);
|
||||
g_autoptr(virPCIDevice) pci = virPCIDeviceNew(&pcisrc->addr);
|
||||
|
||||
if (!pci)
|
||||
return -1;
|
||||
|
||||
if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
|
||||
char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
|
||||
g_autofree char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
|
||||
|
||||
if (!vfioGroupDev) {
|
||||
virPCIDeviceFree(pci);
|
||||
if (!vfioGroupDev)
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = virSecuritySELinuxSetHostdevLabelHelper(vfioGroupDev,
|
||||
false,
|
||||
&data);
|
||||
VIR_FREE(vfioGroupDev);
|
||||
} else {
|
||||
ret = virPCIDeviceFileIterate(pci, virSecuritySELinuxSetPCILabel, &data);
|
||||
}
|
||||
virPCIDeviceFree(pci);
|
||||
break;
|
||||
}
|
||||
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
|
||||
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
|
||||
|
||||
virSCSIDevicePtr scsi =
|
||||
g_autoptr(virSCSIDevice) scsi =
|
||||
virSCSIDeviceNew(NULL,
|
||||
scsihostsrc->adapter, scsihostsrc->bus,
|
||||
scsihostsrc->target, scsihostsrc->unit,
|
||||
@ -2143,13 +2138,11 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
|
||||
ret = virSCSIDeviceFileIterate(scsi,
|
||||
virSecuritySELinuxSetSCSILabel,
|
||||
&data);
|
||||
virSCSIDeviceFree(scsi);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: {
|
||||
virSCSIVHostDevicePtr host = virSCSIVHostDeviceNew(hostsrc->wwpn);
|
||||
g_autoptr(virSCSIVHostDevice) host = virSCSIVHostDeviceNew(hostsrc->wwpn);
|
||||
|
||||
if (!host)
|
||||
return -1;
|
||||
@ -2157,19 +2150,16 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
|
||||
ret = virSCSIVHostDeviceFileIterate(host,
|
||||
virSecuritySELinuxSetHostLabel,
|
||||
&data);
|
||||
virSCSIVHostDeviceFree(host);
|
||||
break;
|
||||
}
|
||||
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
||||
char *vfiodev = NULL;
|
||||
g_autofree char *vfiodev = NULL;
|
||||
|
||||
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
|
||||
return ret;
|
||||
|
||||
ret = virSecuritySELinuxSetHostdevLabelHelper(vfiodev, true, &data);
|
||||
|
||||
VIR_FREE(vfiodev);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -2325,7 +2315,7 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
|
||||
|
||||
switch ((virDomainHostdevSubsysType)dev->source.subsys.type) {
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
|
||||
virUSBDevicePtr usb;
|
||||
g_autoptr(virUSBDevice) usb = NULL;
|
||||
|
||||
if (dev->missing)
|
||||
return 0;
|
||||
@ -2337,37 +2327,31 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
|
||||
return -1;
|
||||
|
||||
ret = virUSBDeviceFileIterate(usb, virSecuritySELinuxRestoreUSBLabel, mgr);
|
||||
virUSBDeviceFree(usb);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
|
||||
virPCIDevicePtr pci =
|
||||
virPCIDeviceNew(&pcisrc->addr);
|
||||
g_autoptr(virPCIDevice) pci = virPCIDeviceNew(&pcisrc->addr);
|
||||
|
||||
if (!pci)
|
||||
return -1;
|
||||
|
||||
if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
|
||||
char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
|
||||
g_autofree char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
|
||||
|
||||
if (!vfioGroupDev) {
|
||||
virPCIDeviceFree(pci);
|
||||
if (!vfioGroupDev)
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = virSecuritySELinuxRestoreFileLabel(mgr, vfioGroupDev, false);
|
||||
VIR_FREE(vfioGroupDev);
|
||||
} else {
|
||||
ret = virPCIDeviceFileIterate(pci, virSecuritySELinuxRestorePCILabel, mgr);
|
||||
}
|
||||
virPCIDeviceFree(pci);
|
||||
break;
|
||||
}
|
||||
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
|
||||
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
|
||||
virSCSIDevicePtr scsi =
|
||||
g_autoptr(virSCSIDevice) scsi =
|
||||
virSCSIDeviceNew(NULL,
|
||||
scsihostsrc->adapter, scsihostsrc->bus,
|
||||
scsihostsrc->target, scsihostsrc->unit,
|
||||
@ -2377,13 +2361,11 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
|
||||
return -1;
|
||||
|
||||
ret = virSCSIDeviceFileIterate(scsi, virSecuritySELinuxRestoreSCSILabel, mgr);
|
||||
virSCSIDeviceFree(scsi);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: {
|
||||
virSCSIVHostDevicePtr host = virSCSIVHostDeviceNew(hostsrc->wwpn);
|
||||
g_autoptr(virSCSIVHostDevice) host = virSCSIVHostDeviceNew(hostsrc->wwpn);
|
||||
|
||||
if (!host)
|
||||
return -1;
|
||||
@ -2391,20 +2373,16 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
|
||||
ret = virSCSIVHostDeviceFileIterate(host,
|
||||
virSecuritySELinuxRestoreHostLabel,
|
||||
mgr);
|
||||
virSCSIVHostDeviceFree(host);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
||||
char *vfiodev = NULL;
|
||||
g_autofree char *vfiodev = NULL;
|
||||
|
||||
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
|
||||
return -1;
|
||||
|
||||
ret = virSecuritySELinuxRestoreFileLabel(mgr, vfiodev, true);
|
||||
|
||||
VIR_FREE(vfiodev);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user