[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 4/4] xen: Avoid VLA
From: |
Anthony PERARD |
Subject: |
[Qemu-devel] [PATCH 4/4] xen: Avoid VLA |
Date: |
Mon, 17 Jun 2019 16:41:05 +0100 |
Avoid using a variable length array.
Signed-off-by: Anthony PERARD <address@hidden>
---
Notes:
Was suggested by Peter here:
<address@hidden>
"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
- [Qemu-devel] [PATCH 0/4] Fix build of Xen support + cleanup, Anthony PERARD, 2019/06/17
- [Qemu-devel] [PATCH 4/4] xen: Avoid VLA,
Anthony PERARD <=
- [Qemu-devel] [PATCH 3/4] xen: Import Xen public headers used by xen-hvm.c, Anthony PERARD, 2019/06/17
- Re: [Qemu-devel] [PATCH 3/4] xen: Import Xen public headers used by xen-hvm.c, Paul Durrant, 2019/06/17
- Re: [Qemu-devel] [PATCH 3/4] xen: Import Xen public headers used by xen-hvm.c, Anthony PERARD, 2019/06/17
- Re: [Qemu-devel] [PATCH 3/4] xen: Import Xen public headers used by xen-hvm.c, Paul Durrant, 2019/06/17
- Re: [Qemu-devel] [Xen-devel] [PATCH 3/4] xen: Import Xen public headers used by xen-hvm.c, Anthony PERARD, 2019/06/17
- Re: [Qemu-devel] [Xen-devel] [PATCH 3/4] xen: Import Xen public headers used by xen-hvm.c, Paul Durrant, 2019/06/18
- Re: [Qemu-devel] [Xen-devel] [PATCH 3/4] xen: Import Xen public headers used by xen-hvm.c, Anthony PERARD, 2019/06/18