thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
77c23f
From 30906c9c78af2710a2b86c096cc7b18bbc4b4e69 Mon Sep 17 00:00:00 2001
77c23f
From: Cornelia Huck <cohuck@redhat.com>
77c23f
Date: Tue, 23 Jun 2020 09:25:38 -0400
77c23f
Subject: [PATCH 04/12] vfio-ccw: Refactor cleanup of regions
77c23f
77c23f
RH-Author: Cornelia Huck <cohuck@redhat.com>
77c23f
Message-id: <20200623092543.358315-5-cohuck@redhat.com>
77c23f
Patchwork-id: 97694
77c23f
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH 4/9] vfio-ccw: Refactor cleanup of regions
77c23f
Bugzilla: 1660916
77c23f
RH-Acked-by: Claudio Imbrenda <cimbrend@redhat.com>
77c23f
RH-Acked-by: David Hildenbrand <david@redhat.com>
77c23f
RH-Acked-by: Thomas Huth <thuth@redhat.com>
77c23f
77c23f
From: Eric Farman <farman@linux.ibm.com>
77c23f
77c23f
While we're at it, add a g_free() for the async_cmd_region that
77c23f
is the last thing currently created.  g_free() knows how to handle
77c23f
NULL pointers, so this makes it easier to remember what cleanups
77c23f
need to be performed when new regions are added.
77c23f
77c23f
Signed-off-by: Eric Farman <farman@linux.ibm.com>
77c23f
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
77c23f
Message-Id: <20200505125757.98209-3-farman@linux.ibm.com>
77c23f
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
77c23f
(cherry picked from commit 2a3b9cbaa7b25a4db4cdcfe1c65279c5464f2923)
77c23f
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
77c23f
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
77c23f
---
77c23f
 hw/vfio/ccw.c | 14 +++++++++-----
77c23f
 1 file changed, 9 insertions(+), 5 deletions(-)
77c23f
77c23f
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
77c23f
index 6bc612b5b7..17eb4c4048 100644
77c23f
--- a/hw/vfio/ccw.c
77c23f
+++ b/hw/vfio/ccw.c
77c23f
@@ -363,8 +363,7 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
77c23f
     vcdev->io_region_size = info->size;
77c23f
     if (sizeof(*vcdev->io_region) != vcdev->io_region_size) {
77c23f
         error_setg(errp, "vfio: Unexpected size of the I/O region");
77c23f
-        g_free(info);
77c23f
-        return;
77c23f
+        goto out_err;
77c23f
     }
77c23f
 
77c23f
     vcdev->io_region_offset = info->offset;
77c23f
@@ -377,15 +376,20 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
77c23f
         vcdev->async_cmd_region_size = info->size;
77c23f
         if (sizeof(*vcdev->async_cmd_region) != vcdev->async_cmd_region_size) {
77c23f
             error_setg(errp, "vfio: Unexpected size of the async cmd region");
77c23f
-            g_free(vcdev->io_region);
77c23f
-            g_free(info);
77c23f
-            return;
77c23f
+            goto out_err;
77c23f
         }
77c23f
         vcdev->async_cmd_region_offset = info->offset;
77c23f
         vcdev->async_cmd_region = g_malloc0(info->size);
77c23f
     }
77c23f
 
77c23f
     g_free(info);
77c23f
+    return;
77c23f
+
77c23f
+out_err:
77c23f
+    g_free(vcdev->async_cmd_region);
77c23f
+    g_free(vcdev->io_region);
77c23f
+    g_free(info);
77c23f
+    return;
77c23f
 }
77c23f
 
77c23f
 static void vfio_ccw_put_region(VFIOCCWDevice *vcdev)
77c23f
-- 
77c23f
2.27.0
77c23f