All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Farman <farman@linux.ibm.com>
To: qemu-devel@nongnu.org, qemu-s390x@nongnu.org
Cc: Halil Pasic <pasic@linux.ibm.com>,
	Jason Herne <jjherne@linux.ibm.com>,
	Eric Farman <farman@linux.ibm.com>,
	Cornelia Huck <cohuck@redhat.com>,
	Jared Rossi <jrossi@linux.ibm.com>
Subject: [PATCH v3 2/7] vfio-ccw: Refactor cleanup of regions
Date: Fri, 17 Apr 2020 04:34:35 +0200	[thread overview]
Message-ID: <20200417023440.70514-3-farman@linux.ibm.com> (raw)
In-Reply-To: <20200417023440.70514-1-farman@linux.ibm.com>

While we're at it, add a g_free() for the async_cmd_region that
is the last thing currently created.  g_free() knows how to handle
NULL pointers, so this makes it easier to remember what cleanups
need to be performed when new regions are added.

Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
---

Notes:
    v1-v2:
     - Add Conny's r-b

 hw/vfio/ccw.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index 50cc2ec75c..ae9e396367 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -370,8 +370,7 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
     vcdev->io_region_size = info->size;
     if (sizeof(*vcdev->io_region) != vcdev->io_region_size) {
         error_setg(errp, "vfio: Unexpected size of the I/O region");
-        g_free(info);
-        return;
+        goto out_err;
     }
 
     vcdev->io_region_offset = info->offset;
@@ -384,15 +383,20 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
         vcdev->async_cmd_region_size = info->size;
         if (sizeof(*vcdev->async_cmd_region) != vcdev->async_cmd_region_size) {
             error_setg(errp, "vfio: Unexpected size of the async cmd region");
-            g_free(vcdev->io_region);
-            g_free(info);
-            return;
+            goto out_err;
         }
         vcdev->async_cmd_region_offset = info->offset;
         vcdev->async_cmd_region = g_malloc0(info->size);
     }
 
     g_free(info);
+    return;
+
+out_err:
+    g_free(vcdev->async_cmd_region);
+    g_free(vcdev->io_region);
+    g_free(info);
+    return;
 }
 
 static void vfio_ccw_put_region(VFIOCCWDevice *vcdev)
-- 
2.17.1



  parent reply	other threads:[~2020-04-17  2:35 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-17  2:34 [PATCH v3 0/7] s390x/vfio-ccw: Channel Path Handling [QEMU] Eric Farman
2020-04-17  2:34 ` [PATCH v3 1/7] linux-headers: update Eric Farman
2020-04-17  2:34 ` Eric Farman [this message]
2020-04-17  2:34 ` [PATCH v3 3/7] vfio-ccw: Add support for the schib region Eric Farman
2020-04-22 11:36   ` Cornelia Huck
2020-04-22 12:17     ` Eric Farman
2020-04-17  2:34 ` [PATCH v3 4/7] vfio-ccw: Add support for the crw region Eric Farman
2020-04-21 12:21   ` Cornelia Huck
2020-04-21 12:57     ` Eric Farman
2020-04-17  2:34 ` [PATCH v3 5/7] vfio-ccw: Refactor ccw irq handler Eric Farman
2020-04-17  2:34 ` [PATCH v3 6/7] s390x/css: Refactor the css_queue_crw() routine Eric Farman
2020-04-21 12:28   ` Cornelia Huck
2020-04-21 13:04     ` Eric Farman
2020-04-17  2:34 ` [PATCH v3 7/7] vfio-ccw: Add support for the CRW irq Eric Farman
2020-04-22 10:38   ` Cornelia Huck
2020-04-17  3:25 ` [PATCH v3 0/7] s390x/vfio-ccw: Channel Path Handling [QEMU] no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200417023440.70514-3-farman@linux.ibm.com \
    --to=farman@linux.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=jjherne@linux.ibm.com \
    --cc=jrossi@linux.ibm.com \
    --cc=pasic@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.