diff mbox series

[14/16] vfio/pci: Use g_autofree for vfio_region_info pointer

Message ID 20240515082041.556571-15-zhenzhong.duan@intel.com
State New
Headers show
Series VFIO: misc cleanups part2 | expand

Commit Message

Duan, Zhenzhong May 15, 2024, 8:20 a.m. UTC
Pointer opregion is freed after vfio_pci_igd_opregion_init().
Use 'g_autofree' to avoid the g_free() calls.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
 hw/vfio/pci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Cédric Le Goater May 21, 2024, 12:48 p.m. UTC | #1
On 5/15/24 10:20, Zhenzhong Duan wrote:
> Pointer opregion is freed after vfio_pci_igd_opregion_init().
> 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>

Thanks,

C.


> ---
>   hw/vfio/pci.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index ecfbb9619f..be87478716 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -3146,7 +3146,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
>   
>       if (!vdev->igd_opregion &&
>           vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) {
> -        struct vfio_region_info *opregion;
> +        g_autofree struct vfio_region_info *opregion = NULL;
>   
>           if (vdev->pdev.qdev.hotplugged) {
>               error_setg(errp,
> @@ -3165,7 +3165,6 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
>           }
>   
>           ret = vfio_pci_igd_opregion_init(vdev, opregion, errp);
> -        g_free(opregion);
>           if (ret) {
>               goto out_teardown;
>           }
diff mbox series

Patch

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index ecfbb9619f..be87478716 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -3146,7 +3146,7 @@  static void vfio_realize(PCIDevice *pdev, Error **errp)
 
     if (!vdev->igd_opregion &&
         vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) {
-        struct vfio_region_info *opregion;
+        g_autofree struct vfio_region_info *opregion = NULL;
 
         if (vdev->pdev.qdev.hotplugged) {
             error_setg(errp,
@@ -3165,7 +3165,6 @@  static void vfio_realize(PCIDevice *pdev, Error **errp)
         }
 
         ret = vfio_pci_igd_opregion_init(vdev, opregion, errp);
-        g_free(opregion);
         if (ret) {
             goto out_teardown;
         }