From: Anthony PERARD <anthony.perard@citrix.com>
To: <qemu-devel@nongnu.org>
Cc: Anthony PERARD <anthony.perard@citrix.com>,
xen-devel@lists.xenproject.org,
Stefano Stabellini <sstabellini@kernel.org>,
Paul Durrant <paul.durrant@citrix.com>
Subject: [Qemu-devel] [PATCH 4/4] xen: Avoid VLA
Date: Mon, 17 Jun 2019 16:41:05 +0100 [thread overview]
Message-ID: <20190617154105.32323-5-anthony.perard@citrix.com> (raw)
In-Reply-To: <20190617154105.32323-1-anthony.perard@citrix.com>
Avoid using a variable length array.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
Notes:
Was suggested by Peter here:
<CAFEAcA88+A2oCkQnxKDEdpmfCZSmPzWMBg01wDDV68bMZoY5Jg@mail.gmail.com>
"should we try to stop using variable length arrays?"
hw/i386/xen/xen-hvm.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
index 725f9c2278..10d73b55b4 100644
--- a/hw/i386/xen/xen-hvm.c
+++ b/hw/i386/xen/xen-hvm.c
@@ -615,7 +615,8 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
{
hwaddr npages = size >> TARGET_PAGE_BITS;
const int width = sizeof(unsigned long) * 8;
- unsigned long bitmap[DIV_ROUND_UP(npages, width)];
+ unsigned long *bitmap = NULL;
+ size_t bitmap_size = DIV_ROUND_UP(npages, width);
int rc, i, j;
const XenPhysmap *physmap = NULL;
@@ -632,6 +633,8 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
return;
}
+ bitmap = g_new0(unsigned long, bitmap_size);
+
rc = xen_track_dirty_vram(xen_domid, start_addr >> TARGET_PAGE_BITS,
npages, bitmap);
if (rc < 0) {
@@ -644,10 +647,10 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
", 0x" TARGET_FMT_plx "): %s\n",
start_addr, start_addr + size, strerror(errno));
}
- return;
+ goto out;
}
- for (i = 0; i < ARRAY_SIZE(bitmap); i++) {
+ for (i = 0; i < bitmap_size; i++) {
unsigned long map = bitmap[i];
while (map != 0) {
j = ctzl(map);
@@ -657,6 +660,8 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
TARGET_PAGE_SIZE);
};
}
+out:
+ g_free(bitmap);
}
static void xen_log_start(MemoryListener *listener,
--
Anthony PERARD
next prev parent reply other threads:[~2019-06-17 16:29 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-17 15:41 [Qemu-devel] [PATCH 0/4] Fix build of Xen support + cleanup Anthony PERARD
2019-06-17 15:41 ` [Qemu-devel] [PATCH 1/4] xen: Fix build with public headers Anthony PERARD
2019-06-17 16:05 ` Paul Durrant
2019-06-17 15:41 ` [Qemu-devel] [PATCH 2/4] xen: Import other xen/io/*.h Anthony PERARD
2019-06-17 16:09 ` Paul Durrant
2019-06-17 15:41 ` [Qemu-devel] [PATCH 3/4] xen: Import Xen public headers used by xen-hvm.c Anthony PERARD
2019-06-17 16:15 ` Paul Durrant
2019-06-17 16:45 ` Anthony PERARD
2019-06-17 16:54 ` Paul Durrant
2019-06-17 17:19 ` [Qemu-devel] [Xen-devel] " Anthony PERARD
2019-06-18 7:55 ` Paul Durrant
2019-06-18 11:05 ` Anthony PERARD
2019-06-17 15:41 ` Anthony PERARD [this message]
2019-06-17 16:39 ` [Qemu-devel] [PATCH 4/4] xen: Avoid VLA Paul Durrant
2019-06-17 17:36 ` Anthony PERARD
2019-06-18 7:50 ` Paul Durrant
2019-06-17 18:09 ` [Qemu-devel] [Xen-devel] [PATCH 0/4] Fix build of Xen support + cleanup 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=20190617154105.32323-5-anthony.perard@citrix.com \
--to=anthony.perard@citrix.com \
--cc=paul.durrant@citrix.com \
--cc=qemu-devel@nongnu.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.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).