diff mbox series

[PULL,20/47] vfio/pci: Use g_autofree in iommufd_cdev_get_info_iova_range()

Message ID 20240522095442.195243-21-clg@redhat.com (mailing list archive)
State New
Headers show
Series [PULL,01/47] vfio: Add Error** argument to .set_dirty_page_tracking() handler | expand

Commit Message

Cédric Le Goater May 22, 2024, 9:54 a.m. UTC
From: Zhenzhong Duan <zhenzhong.duan@intel.com>

Local pointer info is freed before return from
iommufd_cdev_get_info_iova_range().

Use 'g_autofree' to avoid the g_free() calls.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/iommufd.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 8827ffe636e2aba1551ba794bf666a7a214590b7..c6441279728fcede1dde2a099c076ad04c464a1f 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -258,7 +258,7 @@  static int iommufd_cdev_get_info_iova_range(VFIOIOMMUFDContainer *container,
                                             uint32_t ioas_id, Error **errp)
 {
     VFIOContainerBase *bcontainer = &container->bcontainer;
-    struct iommu_ioas_iova_ranges *info;
+    g_autofree struct iommu_ioas_iova_ranges *info = NULL;
     struct iommu_iova_range *iova_ranges;
     int ret, sz, fd = container->be->fd;
 
@@ -291,12 +291,10 @@  static int iommufd_cdev_get_info_iova_range(VFIOIOMMUFDContainer *container,
     }
     bcontainer->pgsizes = info->out_iova_alignment;
 
-    g_free(info);
     return 0;
 
 error:
     ret = -errno;
-    g_free(info);
     error_setg_errno(errp, errno, "Cannot get IOVA ranges");
     return ret;
 }