qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron via <qemu-devel@nongnu.org>
To: <qemu-devel@nongnu.org>, Michael Tsirkin <mst@redhat.com>,
	Fan Ni <fan.ni@samsung.com>, <linux-cxl@vger.kernel.org>
Cc: "Li Zhijian" <lizhijian@cn.fujitsu.com>,
	"Dave Jiang" <dave.jiang@intel.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	linuxarm@huawei.com
Subject: [PATCH 1/4] hw/cxl: Fix CFMW config memory leak
Date: Mon, 4 Sep 2023 14:28:03 +0100	[thread overview]
Message-ID: <20230904132806.6094-2-Jonathan.Cameron@huawei.com> (raw)
In-Reply-To: <20230904132806.6094-1-Jonathan.Cameron@huawei.com>

From: Li Zhijian <lizhijian@cn.fujitsu.com>

Allocate targets and targets[n] resources when all sanity checks are
passed to avoid memory leaks.

Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 hw/cxl/cxl-host.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/cxl/cxl-host.c b/hw/cxl/cxl-host.c
index 034c7805b3..f0920da956 100644
--- a/hw/cxl/cxl-host.c
+++ b/hw/cxl/cxl-host.c
@@ -39,12 +39,6 @@ static void cxl_fixed_memory_window_config(CXLState *cxl_state,
         return;
     }
 
-    fw->targets = g_malloc0_n(fw->num_targets, sizeof(*fw->targets));
-    for (i = 0, target = object->targets; target; i++, target = target->next) {
-        /* This link cannot be resolved yet, so stash the name for now */
-        fw->targets[i] = g_strdup(target->value);
-    }
-
     if (object->size % (256 * MiB)) {
         error_setg(errp,
                    "Size of a CXL fixed memory window must be a multiple of 256MiB");
@@ -64,6 +58,12 @@ static void cxl_fixed_memory_window_config(CXLState *cxl_state,
         fw->enc_int_gran = 0;
     }
 
+    fw->targets = g_malloc0_n(fw->num_targets, sizeof(*fw->targets));
+    for (i = 0, target = object->targets; target; i++, target = target->next) {
+        /* This link cannot be resolved yet, so stash the name for now */
+        fw->targets[i] = g_strdup(target->value);
+    }
+
     cxl_state->fixed_windows = g_list_append(cxl_state->fixed_windows,
                                              g_steal_pointer(&fw));
 
-- 
2.39.2



  reply	other threads:[~2023-09-04 13:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-04 13:28 [PATCH 0/4] hw/cxl: Minor CXL emulation fixes and cleanup Jonathan Cameron via
2023-09-04 13:28 ` Jonathan Cameron via [this message]
2023-09-12 21:22   ` [PATCH 1/4] hw/cxl: Fix CFMW config memory leak Fan Ni
2023-09-13 13:59   ` Michael Tokarev
2023-09-04 13:28 ` [PATCH 2/4] hw/pci-bridge/cxl_upstream: Fix bandwidth entry base unit for SSLBIS Jonathan Cameron via
2023-09-04 13:45   ` Philippe Mathieu-Daudé
2023-09-12 21:23   ` Fan Ni
2023-09-22 20:08   ` Michael Tokarev
2023-09-22 20:59     ` Dave Jiang
2023-09-04 13:28 ` [PATCH 3/4] hw/cxl/cxl_device: Replace magic number in CXLError definition Jonathan Cameron via
2023-09-04 13:46   ` Philippe Mathieu-Daudé
2023-09-04 13:28 ` [PATCH 4/4] docs/cxl: Change to lowercase as others Jonathan Cameron via
2023-09-04 13:46   ` Philippe Mathieu-Daudé
2023-09-12 21:26   ` Fan Ni
2023-09-13  6:38 ` [PATCH 0/4] hw/cxl: Minor CXL emulation fixes and cleanup Philippe Mathieu-Daudé
2023-09-13 14:00 ` Michael Tokarev

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=20230904132806.6094-2-Jonathan.Cameron@huawei.com \
    --to=qemu-devel@nongnu.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=dave.jiang@intel.com \
    --cc=fan.ni@samsung.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=lizhijian@cn.fujitsu.com \
    --cc=mst@redhat.com \
    --cc=philmd@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).