From nobody Sun Feb 8 13:09:42 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1610999682; cv=none; d=zohomail.com; s=zohoarc; b=FfdtIgLzSYAzdCAPWpym7YFAkxuzTntWHFmnlm0v76BuZiXd4239LYB0uOlaziK5C86792qYc0mxBfg2tOR1m6OY621kD1Gfxc3ZY2wTITBeyP/hmw7y487+Vh/dyaJwQ+b+BbVlnv4RS3eKffQS38O4XqyCElKfXKQO0wVMExM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610999682; 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=7bXd3vvbW1wcOtNzLw1YhHuQoIuWrZfyTfg+yKVKq/M=; b=RMaRSBEEEYj5a4BQznFGJbUfrlYu8f3uyEbuxYxf3zq+RkHYJEriCuqkM8sU1ThVNdNLzw2NJcheCFiLgtowpc7rjcV9GZ+V7hoF8Ak+ratnLSpFqOWZYLg0jQBBzaWGUrL0T8G7DWocTQ3sCYrThHORZkZdu4HMsHm+FzZ9gYg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1610999682990982.3408325179978; Mon, 18 Jan 2021 11:54:42 -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-253-2-gsRtMPN9iXDmfzhX0C6w-1; Mon, 18 Jan 2021 14:54:39 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C25A010054FF; Mon, 18 Jan 2021 19:54:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A28B560C9C; Mon, 18 Jan 2021 19:54:28 +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 6F7DC50034; Mon, 18 Jan 2021 19:54:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10IJs24O032488 for ; Mon, 18 Jan 2021 14:54:02 -0500 Received: by smtp.corp.redhat.com (Postfix) id 566F72166B29; Mon, 18 Jan 2021 19:54:02 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5146E2166B28 for ; Mon, 18 Jan 2021 19:54:02 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (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 3D3931875040 for ; Mon, 18 Jan 2021 19:54:02 +0000 (UTC) Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-379-unv3jI4EMuS4mc256QO28Q-1; Mon, 18 Jan 2021 14:54:00 -0500 Received: by mail-qv1-f49.google.com with SMTP id d11so8058739qvo.11 for ; Mon, 18 Jan 2021 11:54:00 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:a75a:cb34:ba60:6de6:be1d]) by smtp.gmail.com with ESMTPSA id 16sm11309085qkf.112.2021.01.18.11.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:53:58 -0800 (PST) X-MC-Unique: 2-gsRtMPN9iXDmfzhX0C6w-1 X-MC-Unique: unv3jI4EMuS4mc256QO28Q-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=7bXd3vvbW1wcOtNzLw1YhHuQoIuWrZfyTfg+yKVKq/M=; b=Za1EJ+Lsdq3FFNhLRbFiSFlAOVmNJejgjjx//JsgMnjTaqwogFYKalPa4OIOFxw0wc 2ThJbn3Urm8dkxfJBwBK0qkVBJVzj8Ffs7I7igL1dKktqUpbMOLGk1EniL5RcmQkcZMB U+WbcaV5wsjiMdOOsAQu/YnpjoDhdiJfZjVte8c57lDINoYehv14hX3MrjgY42nXI8vg U+KCSSGWzjU3aulRB3h1FDSkUz+bqfIixrU6wixZpq6mOn0aFVKnViR7TndqamMEPjEZ U6v3JfJ5weyZmZUekt8yzGLNTIRKCIFY54/DkMBxYrHwiB79Ah2OMd+WHyHog7/Tuyty W+sQ== X-Gm-Message-State: AOAM531KSKyLOILfzVGS/uzJ5WXMbk4gtI6l2lKikwD0N6GlZpwFnpan 9crzD56T3DpQ7bIPIKjRK5mrZoSS94mkUg== X-Google-Smtp-Source: ABdhPJzZKGbU3MI2vRxauR4yQCs9kXpLntSHnaXOI+cIABsjACq168w7iNUK9X3DS1was7AbDsaxeA== X-Received: by 2002:a0c:bd2b:: with SMTP id m43mr1354079qvg.32.1610999639574; Mon, 18 Jan 2021 11:53:59 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH RESEND 08/20] security_dac.c: modernize hostdev label set/restore functions Date: Mon, 18 Jan 2021 16:53:24 -0300 Message-Id: <20210118195336.2090823-9-danielhb413@gmail.com> In-Reply-To: <20210118195336.2090823-1-danielhb413@gmail.com> References: <20210118195336.2090823-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.78 on 10.11.54.6 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.13 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_dac.c | 49 +++++++++++-------------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/src/security/security_dac.c b/src/security/security_dac.c index b5e56feaa8..0085982bb1 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1251,7 +1251,7 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr m= gr, =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; @@ -1262,41 +1262,35 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr= mgr, ret =3D virUSBDeviceFileIterate(usb, virSecurityDACSetUSBLabel, &cbdata); - 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 virSecurityDACSetHostdevLabelHelper(vfioGroupDev, false, &cbdata); - VIR_FREE(vfioGroupDev); } else { ret =3D virPCIDeviceFileIterate(pci, virSecurityDACSetPCILabel, &cbdata); } - - 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, @@ -1308,13 +1302,11 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr= mgr, ret =3D virSCSIDeviceFileIterate(scsi, virSecurityDACSetSCSILabel, &cbdata); - 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; @@ -1322,19 +1314,16 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr= mgr, ret =3D virSCSIVHostDeviceFileIterate(host, virSecurityDACSetHostLabel, &cbdata); - 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 virSecurityDACSetHostdevLabelHelper(vfiodev, true, &cbdata= ); - - VIR_FREE(vfiodev); break; } =20 @@ -1420,7 +1409,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerP= tr 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; @@ -1429,20 +1418,17 @@ virSecurityDACRestoreHostdevLabel(virSecurityManage= rPtr mgr, return -1; =20 ret =3D virUSBDeviceFileIterate(usb, virSecurityDACRestoreUSBLabel= , 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); @@ -1450,17 +1436,15 @@ virSecurityDACRestoreHostdevLabel(virSecurityManage= rPtr mgr, } ret =3D virSecurityDACRestoreFileLabelInternal(mgr, NULL, vfioGroupDev, fal= se); - VIR_FREE(vfioGroupDev); } else { ret =3D virPCIDeviceFileIterate(pci, virSecurityDACRestorePCIL= abel, 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, @@ -1470,13 +1454,11 @@ virSecurityDACRestoreHostdevLabel(virSecurityManage= rPtr mgr, return -1; =20 ret =3D virSCSIDeviceFileIterate(scsi, virSecurityDACRestoreSCSILa= bel, 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; @@ -1484,19 +1466,16 @@ virSecurityDACRestoreHostdevLabel(virSecurityManage= rPtr mgr, ret =3D virSCSIVHostDeviceFileIterate(host, virSecurityDACRestoreHostLabel, 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 virSecurityDACRestoreFileLabel(mgr, vfiodev); - VIR_FREE(vfiodev); break; } =20 --=20 2.26.2