From ef3cb5ba1ced8f885fb8e96c322575cdf281f7d5 Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Mon, 28 May 2018 22:57:09 +0800 Subject: [PATCH] treewide: remove unnecessary unnamed structs/unions According to the syntax defined in C99, each struct/union field must have an identifier. This patch removes unnamed struct/union fields that can be easily expressed in a C99-compatible way. Here is a summary of structs/unions removed. struct vhm_request: union { uint32_t type; uint32_t type; int32_t reserved0[16]; => int32_t reserved0[15]; }; struct vhm_request_buffer: struct vhm_request_buffer { union { union vhm_request_buffer { struct vhm_request ...; => struct vhm_request ...; int8_t reserved[4096]; int8_t reserved[4096]; } } } Signed-off-by: Junjie Mao Reviewed-by: Kevin Tian --- devicemodel/include/public/acrn_common.h | 8 +++----- hypervisor/arch/x86/ept.c | 4 ++-- hypervisor/arch/x86/io.c | 4 ++-- hypervisor/common/hypercall.c | 8 ++++---- hypervisor/common/io_request.c | 8 ++++---- hypervisor/include/public/acrn_common.h | 15 ++++++--------- 6 files changed, 21 insertions(+), 26 deletions(-) diff --git a/devicemodel/include/public/acrn_common.h b/devicemodel/include/public/acrn_common.h index f6b689c7e..4118f3805 100644 --- a/devicemodel/include/public/acrn_common.h +++ b/devicemodel/include/public/acrn_common.h @@ -157,11 +157,9 @@ struct vhm_request { int32_t processed; } __aligned(256); -struct vhm_request_buffer { - union { - struct vhm_request req_queue[VHM_REQUEST_MAX]; - int8_t reserved[4096]; - }; +union vhm_request_buffer { + struct vhm_request req_queue[VHM_REQUEST_MAX]; + int8_t reserved[4096]; } __aligned(4096); /** diff --git a/hypervisor/arch/x86/ept.c b/hypervisor/arch/x86/ept.c index 23c477d53..6eab68d8d 100644 --- a/hypervisor/arch/x86/ept.c +++ b/hypervisor/arch/x86/ept.c @@ -291,9 +291,9 @@ int dm_emulate_mmio_post(struct vcpu *vcpu) { int ret = 0; int cur = vcpu->vcpu_id; - struct vhm_request_buffer *req_buf; + union vhm_request_buffer *req_buf; - req_buf = (struct vhm_request_buffer *)(vcpu->vm->sw.io_shared_page); + req_buf = (union vhm_request_buffer *)(vcpu->vm->sw.io_shared_page); vcpu->req.reqs.mmio_request.value = req_buf->req_queue[cur].reqs.mmio_request.value; diff --git a/hypervisor/arch/x86/io.c b/hypervisor/arch/x86/io.c index 702f4d5a1..67c85572b 100644 --- a/hypervisor/arch/x86/io.c +++ b/hypervisor/arch/x86/io.c @@ -34,12 +34,12 @@ int dm_emulate_pio_post(struct vcpu *vcpu) { int cur = vcpu->vcpu_id; int cur_context = vcpu->arch_vcpu.cur_context; - struct vhm_request_buffer *req_buf = NULL; + union vhm_request_buffer *req_buf = NULL; uint32_t mask = 0xFFFFFFFFul >> (32 - 8 * vcpu->req.reqs.pio_request.size); uint64_t *rax; - req_buf = (struct vhm_request_buffer *)(vcpu->vm->sw.io_shared_page); + req_buf = (union vhm_request_buffer *)(vcpu->vm->sw.io_shared_page); rax = &vcpu->arch_vcpu.contexts[cur_context].guest_cpu_regs.regs.rax; vcpu->req.reqs.pio_request.value = diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index 2fadcb224..4c00cd7c3 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -353,9 +353,9 @@ static void complete_request(struct vcpu *vcpu) * mark ioreq done and don't resume vcpu. */ if (vcpu->state == VCPU_ZOMBIE) { - struct vhm_request_buffer *req_buf; + union vhm_request_buffer *req_buf; - req_buf = (struct vhm_request_buffer *) + req_buf = (union vhm_request_buffer *) vcpu->vm->sw.io_shared_page; req_buf->req_queue[vcpu->vcpu_id].valid = false; atomic_store(&vcpu->ioreq_pending, 0); @@ -382,7 +382,7 @@ static void complete_request(struct vcpu *vcpu) int64_t hcall_notify_req_finish(uint64_t vmid, uint64_t vcpu_id) { int64_t ret = 0; - struct vhm_request_buffer *req_buf; + union vhm_request_buffer *req_buf; struct vhm_request *req; struct vcpu *vcpu; struct vm *target_vm = get_vm_from_vmid(vmid); @@ -397,7 +397,7 @@ int64_t hcall_notify_req_finish(uint64_t vmid, uint64_t vcpu_id) vcpu = vcpu_from_vid(target_vm, vcpu_id); ASSERT(vcpu != NULL, "Failed to get VCPU context."); - req_buf = (struct vhm_request_buffer *)target_vm->sw.io_shared_page; + req_buf = (union vhm_request_buffer *)target_vm->sw.io_shared_page; req = req_buf->req_queue + vcpu_id; if (req->valid && diff --git a/hypervisor/common/io_request.c b/hypervisor/common/io_request.c index 19cd48b6a..cdb6c0367 100644 --- a/hypervisor/common/io_request.c +++ b/hypervisor/common/io_request.c @@ -57,7 +57,7 @@ static void acrn_print_request(int vcpu_id, struct vhm_request *req) int acrn_insert_request_wait(struct vcpu *vcpu, struct vhm_request *req) { - struct vhm_request_buffer *req_buf = NULL; + union vhm_request_buffer *req_buf = NULL; long cur; ASSERT(sizeof(*req) == (4096/VHM_REQUEST_MAX), @@ -67,7 +67,7 @@ int acrn_insert_request_wait(struct vcpu *vcpu, struct vhm_request *req) if (!vcpu || !req || vcpu->vm->sw.io_shared_page == NULL) return -EINVAL; - req_buf = (struct vhm_request_buffer *)(vcpu->vm->sw.io_shared_page); + req_buf = (union vhm_request_buffer *)(vcpu->vm->sw.io_shared_page); /* ACRN insert request to VHM and inject upcall */ cur = vcpu->vcpu_id; @@ -146,7 +146,7 @@ static void _get_req_info_(struct vhm_request *req, int *id, char *type, int get_req_info(char *str, int str_max) { int i, len, size = str_max, client_id; - struct vhm_request_buffer *req_buf; + union vhm_request_buffer *req_buf; struct vhm_request *req; char type[16], state[16], dir[16]; long addr, val; @@ -161,7 +161,7 @@ int get_req_info(char *str, int str_max) spinlock_obtain(&vm_list_lock); list_for_each(pos, &vm_list) { vm = list_entry(pos, struct vm, list); - req_buf = (struct vhm_request_buffer *)vm->sw.io_shared_page; + req_buf = (union vhm_request_buffer *)vm->sw.io_shared_page; if (req_buf) { for (i = 0; i < VHM_REQUEST_MAX; i++) { req = req_buf->req_queue + i; diff --git a/hypervisor/include/public/acrn_common.h b/hypervisor/include/public/acrn_common.h index 7ff42f9a0..d2c050dde 100644 --- a/hypervisor/include/public/acrn_common.h +++ b/hypervisor/include/public/acrn_common.h @@ -110,10 +110,9 @@ struct pci_request { /* vhm_request are 256Bytes aligned */ struct vhm_request { /* offset: 0bytes - 63bytes */ - union { - uint32_t type; - int32_t reserved0[16]; - }; + uint32_t type; + int32_t reserved0[15]; + /* offset: 64bytes-127bytes */ union { struct pio_request pio_request; @@ -138,11 +137,9 @@ struct vhm_request { int32_t processed; } __aligned(256); -struct vhm_request_buffer { - union { - struct vhm_request req_queue[VHM_REQUEST_MAX]; - int8_t reserved[4096]; - }; +union vhm_request_buffer { + struct vhm_request req_queue[VHM_REQUEST_MAX]; + int8_t reserved[4096]; } __aligned(4096); /**