From da0f28c6ded7c9733d61bd7e50122448a48b500f Mon Sep 17 00:00:00 2001 From: "Yang, Yu-chu" Date: Wed, 18 Jul 2018 18:16:56 -0700 Subject: [PATCH] HV: Bracket for the same level of precendence The plus and minor have the same level of precedence. The Misra-C considers it as a violation. Added brackets in between addition and substraction oprators. Signed-off-by: Yang, Yu-chu Acked-by: Anthony Xu --- hypervisor/arch/x86/guest/guest.c | 6 +++--- hypervisor/arch/x86/guest/ucode.c | 2 +- hypervisor/arch/x86/trusty.c | 2 +- hypervisor/include/arch/x86/mmu.h | 3 ++- hypervisor/include/lib/util.h | 2 +- hypervisor/lib/memory.c | 6 +++--- hypervisor/lib/sprintf.c | 4 ++-- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/hypervisor/arch/x86/guest/guest.c b/hypervisor/arch/x86/guest/guest.c index 74f6cc3b1..e0720fe18 100644 --- a/hypervisor/arch/x86/guest/guest.c +++ b/hypervisor/arch/x86/guest/guest.c @@ -649,7 +649,7 @@ uint64_t e820_alloc_low_memory(uint32_t size) struct e820_entry *entry, *new_entry; /* We want memory in page boundary and integral multiple of pages */ - size = ((size + CPU_PAGE_SIZE - 1U) >> CPU_PAGE_SHIFT) + size = (((size + CPU_PAGE_SIZE) - 1U) >> CPU_PAGE_SHIFT) << CPU_PAGE_SHIFT; for (i = 0U; i < e820_entries; i++) { @@ -682,8 +682,8 @@ uint64_t e820_alloc_low_memory(uint32_t size) new_entry = &e820[e820_entries]; new_entry->type = E820_TYPE_RESERVED; new_entry->baseaddr = end - size; - new_entry->length = entry->baseaddr + - entry->length - new_entry->baseaddr; + new_entry->length = (entry->baseaddr + + entry->length) - new_entry->baseaddr; /* Shrink the existing entry and total available memory */ entry->length -= new_entry->length; diff --git a/hypervisor/arch/x86/guest/ucode.c b/hypervisor/arch/x86/guest/ucode.c index 5d8031d21..a408c3461 100644 --- a/hypervisor/arch/x86/guest/ucode.c +++ b/hypervisor/arch/x86/guest/ucode.c @@ -48,7 +48,7 @@ void acrn_update_ucode(struct vcpu *vcpu, uint64_t v) data_size = UCODE_GET_DATA_SIZE(uhdr) + sizeof(struct ucode_header); data_page_num = - (data_size + CPU_PAGE_SIZE - 1U) >> CPU_PAGE_SHIFT; + ((data_size + CPU_PAGE_SIZE) - 1U) >> CPU_PAGE_SHIFT; ucode_ptr = alloc_pages(data_page_num); if (ucode_ptr == NULL) { diff --git a/hypervisor/arch/x86/trusty.c b/hypervisor/arch/x86/trusty.c index 57c1fa6fb..304692cc9 100644 --- a/hypervisor/arch/x86/trusty.c +++ b/hypervisor/arch/x86/trusty.c @@ -481,7 +481,7 @@ bool initialize_trusty(struct vcpu *vcpu, uint64_t param) /* init secure world environment */ if (init_secure_world_env(vcpu, - trusty_entry_gpa - trusty_base_gpa + TRUSTY_EPT_REBASE_GPA, + (trusty_entry_gpa - trusty_base_gpa) + TRUSTY_EPT_REBASE_GPA, trusty_base_hpa, trusty_mem_size)) { /* switch to Secure World */ diff --git a/hypervisor/include/arch/x86/mmu.h b/hypervisor/include/arch/x86/mmu.h index d99021825..935dfbd1d 100644 --- a/hypervisor/include/arch/x86/mmu.h +++ b/hypervisor/include/arch/x86/mmu.h @@ -210,7 +210,8 @@ #define MMU_MEM_ATTR_TYPE_MASK \ (IA32E_PDPTE_PAT_BIT | IA32E_COMM_PCD_BIT | IA32E_COMM_PWT_BIT) -#define ROUND_PAGE_UP(addr) (((addr) + (uint64_t)CPU_PAGE_SIZE - 1UL) & CPU_PAGE_MASK) +#define ROUND_PAGE_UP(addr) \ + ((((addr) + (uint64_t)CPU_PAGE_SIZE) - 1UL) & CPU_PAGE_MASK) #define ROUND_PAGE_DOWN(addr) ((addr) & CPU_PAGE_MASK) enum _page_table_type { diff --git a/hypervisor/include/lib/util.h b/hypervisor/include/lib/util.h index e42cf009c..7a0f164cf 100644 --- a/hypervisor/include/lib/util.h +++ b/hypervisor/include/lib/util.h @@ -18,7 +18,7 @@ #define offsetof(st, m) __builtin_offsetof(st, m) /** Roundup (x/y) to ( x/y + (x%y) ? 1 : 0) **/ -#define INT_DIV_ROUNDUP(x, y) (((x)+(y)-1)/(y)) +#define INT_DIV_ROUNDUP(x, y) ((((x)+(y))-1)/(y)) #define min(x, y) ((x) < (y)) ? (x) : (y) diff --git a/hypervisor/lib/memory.c b/hypervisor/lib/memory.c index 48fe31d7a..fb31b3047 100644 --- a/hypervisor/lib/memory.c +++ b/hypervisor/lib/memory.c @@ -245,7 +245,7 @@ void *malloc(unsigned int num_bytes) memory = allocate_mem(&Memory_Pool, num_bytes); } else { uint32_t page_num = - (num_bytes + CPU_PAGE_SIZE - 1U) >> CPU_PAGE_SHIFT; + ((num_bytes + CPU_PAGE_SIZE) - 1U) >> CPU_PAGE_SHIFT; /* Request memory allocation through alloc_page */ memory = alloc_pages(page_num); } @@ -361,8 +361,8 @@ void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen) ASSERT(false); } - if (((d > s) && (d <= (s + slen - 1U))) - || ((d < s) && (s <= (d + dmax - 1U)))) { + if (((d > s) && (d <= ((s + slen) - 1U))) + || ((d < s) && (s <= ((d + dmax) - 1U)))) { ASSERT(false); } diff --git a/hypervisor/lib/sprintf.c b/hypervisor/lib/sprintf.c index 80be9b473..016d7f17e 100644 --- a/hypervisor/lib/sprintf.c +++ b/hypervisor/lib/sprintf.c @@ -335,7 +335,7 @@ static int print_pow2(struct print_param *param, /* assign parameter and apply width and precision */ param->vars.value = pos; - param->vars.valuelen = digitbuff + sizeof(digitbuff) - pos; + param->vars.valuelen = (digitbuff + sizeof(digitbuff)) - pos; ret = format_number(param); @@ -408,7 +408,7 @@ static int print_decimal(struct print_param *param, int64_t value) /* assign parameter and apply width and precision */ param->vars.value = pos; - param->vars.valuelen = digitbuff + sizeof(digitbuff) - pos; + param->vars.valuelen = (digitbuff + sizeof(digitbuff)) - pos; ret = format_number(param);