yeahuh / rpms / qemu-kvm

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