From d682a4598ef40f4e0a83f3630d1bc0b2514c1e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Peixoto?= Date: Tue, 22 Oct 2024 17:50:07 +0100 Subject: [PATCH] fix(core/remio): use of zero-sized array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The specific error is triggered in the macro expansion for OBJPOOL_ALLOC when the value CONFIG_REMIO_DEV_NUM assumes the value of 0. To solve this problem, we allocate only one slot if the user does not configure any Remote I/O device. Note: While we could use the #if macro to define the object pool only when a Remote I/O is configured, this approach would clutter the code with constant checks for device configuration whenever accessing certain variables. Signed-off-by: João Peixoto --- src/core/remio.c | 3 ++- src/core/vm.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/remio.c b/src/core/remio.c index f53bc856..1f8ed4f8 100644 --- a/src/core/remio.c +++ b/src/core/remio.c @@ -138,7 +138,8 @@ static void remio_cpu_handler(uint32_t event, uint64_t data); CPU_MSG_HANDLER(remio_cpu_handler, REMIO_CPUMSG_ID) /** Object pool to allocate Remote I/O devices */ -OBJPOOL_ALLOC(remio_device_pool, struct remio_device, CONFIG_REMIO_DEV_NUM); +OBJPOOL_ALLOC(remio_device_pool, struct remio_device, + CONFIG_REMIO_DEV_NUM ? CONFIG_REMIO_DEV_NUM : 1); /** Object pool to allocate pending Remote I/O requests events */ OBJPOOL_ALLOC(remio_request_event_pool, struct remio_request_event, REMIO_VCPU_NUM); diff --git a/src/core/vm.c b/src/core/vm.c index 08e2d1aa..669a32d5 100644 --- a/src/core/vm.c +++ b/src/core/vm.c @@ -11,7 +11,7 @@ #include #include -OBJPOOL_ALLOC(emul_cache, struct emul_mem, CONFIG_REMIO_DEV_NUM); +OBJPOOL_ALLOC(emul_cache, struct emul_mem, CONFIG_REMIO_DEV_NUM ? CONFIG_REMIO_DEV_NUM : 1); static void vm_master_init(struct vm* vm, const struct vm_config* vm_config, vmid_t vm_id) {