[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 06/23] hw/block/dataplane/virtio-blk: Avoid dynamic stack allocat
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 06/23] hw/block/dataplane/virtio-blk: Avoid dynamic stack allocation |
Date: |
Wed, 5 May 2021 23:10:30 +0200 |
Use autofree heap allocation instead of variable-length
array on the stack.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
hw/block/dataplane/virtio-blk.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index e9050c8987e..53f5e4d8aa6 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -60,11 +60,12 @@ static void notify_guest_bh(void *opaque)
{
VirtIOBlockDataPlane *s = opaque;
unsigned nvqs = s->conf->num_queues;
- unsigned long bitmap[BITS_TO_LONGS(nvqs)];
+ long bitmap_nr = BITS_TO_LONGS(nvqs);
+ g_autofree unsigned long *bitmap = g_new(unsigned long, bitmap_nr);
unsigned j;
- memcpy(bitmap, s->batch_notify_vqs, sizeof(bitmap));
- memset(s->batch_notify_vqs, 0, sizeof(bitmap));
+ memcpy(bitmap, s->batch_notify_vqs, bitmap_nr * sizeof(*bitmap));
+ memset(s->batch_notify_vqs, 0, bitmap_nr * sizeof(*bitmap));
for (j = 0; j < nvqs; j += BITS_PER_LONG) {
unsigned long bits = bitmap[j / BITS_PER_LONG];
--
2.26.3
- Re: [PATCH 03/23] chardev/baum: Use definitions to avoid dynamic stack allocation, (continued)
[PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05