From nobody Sat Feb 7 11:05:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1609764930; cv=none; d=zohomail.com; s=zohoarc; b=iMS3gFBHRWgx4xVxPe/6wPNnSoxDmsJEg0Rtq6f5HtHokQ41DY9RnTUo2XMxFFockiBF4CbEUQ3sMvxyGCxalx2aMw6kjlYLJtS+gcYjMXcJaJXfz/WsWE/UH4ufRsqkR7aqcZUv+Uws9Rzu+t0/bxPKyfSWOvBbCz9AVOl7C14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764930; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MpuBZWrkJlYtDmUT0hu4LKujruVaBq4a04ooDfgwiZI=; b=gc0iLP+seBC2CjwgfVL058+6aglNXf2L0hO/D/8tYkJ5OVdTTplX2bp1khbNOD+HguNuhQnLVIO+IzbIcb/VkZKCop88iIMUNp1oqahupjzcRUzckcVURR+A7u7mJwBppaK4Q6tw9NS6H86387TbTYB2DOXjeWV3FvDUrsjymn8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609764930977943.5415945256225; Mon, 4 Jan 2021 04:55:30 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-578-rCO7dbLjN6msIINEjXLkcw-1; Mon, 04 Jan 2021 07:55:27 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1129883DC6E; Mon, 4 Jan 2021 12:55:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E14F55D761; Mon, 4 Jan 2021 12:55:21 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id AD6FB1809CA8; Mon, 4 Jan 2021 12:55:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtCc7014184 for ; Mon, 4 Jan 2021 07:55:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 574659D498; Mon, 4 Jan 2021 12:55:12 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 522CB7AF6 for ; Mon, 4 Jan 2021 12:55:12 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3F5AE811E78 for ; Mon, 4 Jan 2021 12:55:12 +0000 (UTC) Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-524-eU_DHXhDNfaf2iRn0aX04g-1; Mon, 04 Jan 2021 07:55:10 -0500 Received: by mail-qk1-f172.google.com with SMTP id 186so23231327qkj.3 for ; Mon, 04 Jan 2021 04:55:10 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:08 -0800 (PST) X-MC-Unique: rCO7dbLjN6msIINEjXLkcw-1 X-MC-Unique: eU_DHXhDNfaf2iRn0aX04g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MpuBZWrkJlYtDmUT0hu4LKujruVaBq4a04ooDfgwiZI=; b=RezkoOMZniKSIxl1KN0/8zCj7enHRETzDCTzT9QvU8rJG0buCu2F7C3V81hLjFnUok X6OCr26v3EszWnORx8yGSq1bQWlfnSD3lfjr9igHDNJqGfy5Pq+onB3FfdR0qZPJ3K1x ac9QP4jY8WtiumX3XEd1dUBb9j6KLOszL1NascrYs+hT114a6692SgF9fGlX4c8+ZqJX 5v/o5Z1H4aJ4y4Y7gupCJ0sXXNe7D9nkPX0lu8sH8ppQ7HUYlXs5VwtjlRMTGgGCXCri h7J5xtav51sNyl5ntF4YRS0pqibCR1NNtxBxvpO/WQV5k9m9ItMO30siJ3jtiGI3zZ+w ybLQ== X-Gm-Message-State: AOAM532w21DgASdQeJbj7ifi7pK/ZwpT79sTiX6L/xZIJ1+ClVRSkIMQ TbftvdrRv9OAx3UNEW0CPbHKaVX6MmQQnA== X-Google-Smtp-Source: ABdhPJyQ3+nMdTPMlknglrVGnv6WrXCIn+buBA/PIx0TDYTib2nDv1b1Woq3jQ8Pv+OiQYEwbzlGbA== X-Received: by 2002:a37:8703:: with SMTP id j3mr63333147qkd.455.1609764909434; Mon, 04 Jan 2021 04:55:09 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 07/20] security_selinux.c: modernize set/restore hostdev subsys label functions Date: Mon, 4 Jan 2021 09:54:31 -0300 Message-Id: <20210104125444.200536-8-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use g_auto* cleanup to avoid free() calls. Signed-off-by: Daniel Henrique Barboza --- src/security/security_selinux.c | 54 ++++++++++----------------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index c43d326314..bf53932ccc 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2086,7 +2086,7 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityMa= nagerPtr mgr, =20 switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { - virUSBDevicePtr usb; + g_autoptr(virUSBDevice) usb =3D NULL; =20 if (dev->missing) return 0; @@ -2098,39 +2098,34 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurity= ManagerPtr mgr, return -1; =20 ret =3D virUSBDeviceFileIterate(usb, virSecuritySELinuxSetUSBLabel= , &data); - virUSBDeviceFree(usb); break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - virPCIDevicePtr pci =3D - virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; =20 if (pcisrc->backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { - char *vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev(pci); + g_autofree char *vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev= (pci); =20 - if (!vfioGroupDev) { - virPCIDeviceFree(pci); + if (!vfioGroupDev) return -1; - } + ret =3D virSecuritySELinuxSetHostdevLabelHelper(vfioGroupDev, false, &data); - VIR_FREE(vfioGroupDev); } else { ret =3D virPCIDeviceFileIterate(pci, virSecuritySELinuxSetPCIL= abel, &data); } - virPCIDeviceFree(pci); break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: { virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; =20 - virSCSIDevicePtr scsi =3D + g_autoptr(virSCSIDevice) scsi =3D virSCSIDeviceNew(NULL, scsihostsrc->adapter, scsihostsrc->bus, scsihostsrc->target, scsihostsrc->unit, @@ -2142,13 +2137,11 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurity= ManagerPtr mgr, ret =3D virSCSIDeviceFileIterate(scsi, virSecuritySELinuxSetSCSILabel, &data); - virSCSIDeviceFree(scsi); - break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: { - virSCSIVHostDevicePtr host =3D virSCSIVHostDeviceNew(hostsrc->wwpn= ); + g_autoptr(virSCSIVHostDevice) host =3D virSCSIVHostDeviceNew(hosts= rc->wwpn); =20 if (!host) return -1; @@ -2156,19 +2149,16 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurity= ManagerPtr mgr, ret =3D virSCSIVHostDeviceFileIterate(host, virSecuritySELinuxSetHostLabel, &data); - virSCSIVHostDeviceFree(host); break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { - char *vfiodev =3D NULL; + g_autofree char *vfiodev =3D NULL; =20 if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) return ret; =20 ret =3D virSecuritySELinuxSetHostdevLabelHelper(vfiodev, true, &da= ta); - - VIR_FREE(vfiodev); break; } =20 @@ -2324,7 +2314,7 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecuri= tyManagerPtr mgr, =20 switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { - virUSBDevicePtr usb; + g_autoptr(virUSBDevice) usb =3D NULL; =20 if (dev->missing) return 0; @@ -2336,37 +2326,31 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecu= rityManagerPtr mgr, return -1; =20 ret =3D virUSBDeviceFileIterate(usb, virSecuritySELinuxRestoreUSBL= abel, mgr); - virUSBDeviceFree(usb); - break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - virPCIDevicePtr pci =3D - virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; =20 if (pcisrc->backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { - char *vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev(pci); + g_autofree char *vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev= (pci); =20 - if (!vfioGroupDev) { - virPCIDeviceFree(pci); + if (!vfioGroupDev) return -1; - } + ret =3D virSecuritySELinuxRestoreFileLabel(mgr, vfioGroupDev, = false); - VIR_FREE(vfioGroupDev); } else { ret =3D virPCIDeviceFileIterate(pci, virSecuritySELinuxRestore= PCILabel, mgr); } - virPCIDeviceFree(pci); break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: { virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; - virSCSIDevicePtr scsi =3D + g_autoptr(virSCSIDevice) scsi =3D virSCSIDeviceNew(NULL, scsihostsrc->adapter, scsihostsrc->bus, scsihostsrc->target, scsihostsrc->unit, @@ -2376,13 +2360,11 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecu= rityManagerPtr mgr, return -1; =20 ret =3D virSCSIDeviceFileIterate(scsi, virSecuritySELinuxRestoreSC= SILabel, mgr); - virSCSIDeviceFree(scsi); - break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: { - virSCSIVHostDevicePtr host =3D virSCSIVHostDeviceNew(hostsrc->wwpn= ); + g_autoptr(virSCSIVHostDevice) host =3D virSCSIVHostDeviceNew(hosts= rc->wwpn); =20 if (!host) return -1; @@ -2390,20 +2372,16 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecu= rityManagerPtr mgr, ret =3D virSCSIVHostDeviceFileIterate(host, virSecuritySELinuxRestoreHostL= abel, mgr); - virSCSIVHostDeviceFree(host); - break; } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { - char *vfiodev =3D NULL; + g_autofree char *vfiodev =3D NULL; =20 if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) return -1; =20 ret =3D virSecuritySELinuxRestoreFileLabel(mgr, vfiodev, true); - - VIR_FREE(vfiodev); break; } =20 --=20 2.26.2