From nobody Mon Nov 25 10:31:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1716353029; cv=none; d=zohomail.com; s=zohoarc; b=cZT7v3XAB0O9CE9aoh/sL0BQU57pYAxDxlZT4L5nmX+yvTN7+nYbYp0JrCz7oWgKcpGZpKZm46j8ZRE65oJelonabIuO7nKLFBdvtpt7SYuEvMCBrnrBZ5I6fhDslrKmrx1lj6C/vzZ3e2es3TcuTWw3821UC05/4Triz7R9NA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716353029; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zhPBCKktofhJK+AVTdKcq02t6h9EdJuOnYLASrBedE0=; b=jkeWFmKi1KiPTzG7+IrlgG8af/rvqRNe3xdUI0tqCw/DCwB7/56UWqFUF8TF6y2kPwFhpMLYx2sjj/Td6g8LBTlDDG0K1YSo/lVQrt5HQKc028M52E1xPpWD0RjdLmEsSaQHY/aFdgVfADMSVECc65rg5lX1VpuqNDWPpuZbw8A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1716353029150720.5525863555978; Tue, 21 May 2024 21:43:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9dpB-0001zs-TK; Wed, 22 May 2024 00:43:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9dp9-0001p8-L8 for qemu-devel@nongnu.org; Wed, 22 May 2024 00:43:35 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9dp7-0005wQ-Go for qemu-devel@nongnu.org; Wed, 22 May 2024 00:43:35 -0400 Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 21:43:17 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 21:43:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716353013; x=1747889013; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=r1ujOT9wnmzL4Jy0xbnj8LOr9Q4ivRZVm5w7T144XKg=; b=Bs+enfOPnGSJArIRggqiEGdLxeKLcmeMdvv49wWMd2v4/n+2dBjyKyn2 nVBEXM8o4bOdcQnbu4oIY91XMaCN8x6TxnKsBTF8TyrNq7AJpzB3YyUYE szx0MCe1dyouOq1FxS4yQaP8MO2tO2oLBMad92ZHedSAA38yvgjlR+/Je ZjRPnJMw+bUXKzWxMmQ8bYWgxIAVHBNDVL0LdVA1mywVgJKqx79K2KdWX gCdx417OYbE2tx4SIpH4zT3TPD0kmrHi3RIyzciy9P3u6NAU5pA1SC9ou paClis4h67tj/x+bnx2/kKfVGQBgI7UxQYzOJMwhMM1BdfkQxT6lG8fUl Q==; X-CSE-ConnectionGUID: nO8fOkpuRfy7b24YXrGWSA== X-CSE-MsgGUID: 5CWtU9nmSFqeaVFyT1I+4w== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="23994210" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="23994210" X-CSE-ConnectionGUID: 1Tf3vL9JQ4Kc2Y4/nZIUog== X-CSE-MsgGUID: 8IjPgqwIQ8mvZp6ikIf7IQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33683795" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v2 17/20] vfio: Use g_autofree in all call site of vfio_get_region_info() Date: Wed, 22 May 2024 12:40:12 +0800 Message-Id: <20240522044015.412951-18-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522044015.412951-1-zhenzhong.duan@intel.com> References: <20240522044015.412951-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1716353030296100002 There are some exceptions when pointer to vfio_region_info is reused. In that case, the pointed memory is freed manually. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan --- hw/vfio/helpers.c | 7 ++----- hw/vfio/igd.c | 5 ++--- hw/vfio/pci.c | 13 +++---------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 4b079dc383..27ea26aa48 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -343,7 +343,7 @@ static int vfio_setup_region_sparse_mmaps(VFIORegion *r= egion, int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *regio= n, int index, const char *name) { - struct vfio_region_info *info; + g_autofree struct vfio_region_info *info =3D NULL; int ret; =20 ret =3D vfio_get_region_info(vbasedev, index, &info); @@ -376,8 +376,6 @@ int vfio_region_setup(Object *obj, VFIODevice *vbasedev= , VFIORegion *region, } } =20 - g_free(info); - trace_vfio_region_setup(vbasedev->name, index, name, region->flags, region->fd_offset, region->size= ); return 0; @@ -594,14 +592,13 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, ui= nt32_t type, =20 bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_ty= pe) { - struct vfio_region_info *info =3D NULL; + g_autofree struct vfio_region_info *info =3D NULL; bool ret =3D false; =20 if (!vfio_get_region_info(vbasedev, region, &info)) { if (vfio_get_region_info_cap(info, cap_type)) { ret =3D true; } - g_free(info); } =20 return ret; diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 402fc5ce1d..1e79202f2b 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -367,8 +367,8 @@ static const MemoryRegionOps vfio_igd_index_quirk =3D { =20 void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) { - struct vfio_region_info *rom =3D NULL, *opregion =3D NULL, - *host =3D NULL, *lpc =3D NULL; + g_autofree struct vfio_region_info *rom =3D NULL; + struct vfio_region_info *opregion =3D NULL, *host =3D NULL, *lpc =3D N= ULL; VFIOQuirk *quirk; VFIOIGDQuirk *igd; PCIDevice *lpc_bridge; @@ -609,7 +609,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, ggms_mb + gms_mb); =20 out: - g_free(rom); g_free(opregion); g_free(host); g_free(lpc); diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 35ad9b582f..74a79bdf61 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -879,7 +879,7 @@ static void vfio_update_msi(VFIOPCIDevice *vdev) =20 static void vfio_pci_load_rom(VFIOPCIDevice *vdev) { - struct vfio_region_info *reg_info; + g_autofree struct vfio_region_info *reg_info =3D NULL; uint64_t size; off_t off =3D 0; ssize_t bytes; @@ -897,8 +897,6 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev) vdev->rom_size =3D size =3D reg_info->size; vdev->rom_offset =3D reg_info->offset; =20 - g_free(reg_info); - if (!vdev->rom_size) { vdev->rom_read_failed =3D true; error_report("vfio-pci: Cannot read device rom at " @@ -2668,7 +2666,7 @@ static VFIODeviceOps vfio_pci_ops =3D { bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp) { VFIODevice *vbasedev =3D &vdev->vbasedev; - struct vfio_region_info *reg_info; + g_autofree struct vfio_region_info *reg_info =3D NULL; int ret; =20 ret =3D vfio_get_region_info(vbasedev, VFIO_PCI_VGA_REGION_INDEX, ®= _info); @@ -2685,7 +2683,6 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **e= rrp) error_setg(errp, "unexpected VGA info, flags 0x%lx, size 0x%lx", (unsigned long)reg_info->flags, (unsigned long)reg_info->size); - g_free(reg_info); return false; } =20 @@ -2694,8 +2691,6 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **e= rrp) vdev->vga->fd_offset =3D reg_info->offset; vdev->vga->fd =3D vdev->vbasedev.fd; =20 - g_free(reg_info); - vdev->vga->region[QEMU_PCI_VGA_MEM].offset =3D QEMU_PCI_VGA_MEM_BASE; vdev->vga->region[QEMU_PCI_VGA_MEM].nr =3D QEMU_PCI_VGA_MEM; QLIST_INIT(&vdev->vga->region[QEMU_PCI_VGA_MEM].quirks); @@ -2736,7 +2731,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **e= rrp) static bool vfio_populate_device(VFIOPCIDevice *vdev, Error **errp) { VFIODevice *vbasedev =3D &vdev->vbasedev; - struct vfio_region_info *reg_info; + g_autofree struct vfio_region_info *reg_info =3D NULL; struct vfio_irq_info irq_info =3D { .argsz =3D sizeof(irq_info) }; int i, ret =3D -1; =20 @@ -2790,8 +2785,6 @@ static bool vfio_populate_device(VFIOPCIDevice *vdev,= Error **errp) } vdev->config_offset =3D reg_info->offset; =20 - g_free(reg_info); - if (vdev->features & VFIO_FEATURE_ENABLE_VGA) { if (!vfio_populate_vga(vdev, errp)) { error_append_hint(errp, "device does not support " --=20 2.34.1