From a1ac585b85c221ea8883f3f9ae5a0fc1c9a77b48 Mon Sep 17 00:00:00 2001 From: "Li, Fei1" Date: Tue, 27 Nov 2018 23:46:46 +0800 Subject: [PATCH] hv: add brackets to make operator expression more readable v1-v2: Bypass this case: When binary arithmetic operators of different precedence (e.g. '+' and '*') are mixed in an expression, parentheses are added to the sub-expressions using the operator with a higher precedence. v1: The operator precedence rules are complicated and it is easy to make a mistake. So add brackets to make operator expression more readable. Tracked-On: #861 Signed-off-by: Li, Fei1 --- hypervisor/arch/x86/io.c | 4 ++-- hypervisor/arch/x86/trusty.c | 2 +- hypervisor/common/hypercall.c | 4 ++-- hypervisor/debug/profiling.c | 6 +++--- hypervisor/lib/crypto/mbedtls/hkdf.c | 2 +- hypervisor/lib/sprintf.c | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hypervisor/arch/x86/io.c b/hypervisor/arch/x86/io.c index 0620db0b6..a7ca57115 100644 --- a/hypervisor/arch/x86/io.c +++ b/hypervisor/arch/x86/io.c @@ -259,9 +259,9 @@ hv_emulate_mmio(struct acrn_vcpu *vcpu, struct io_request *io_req) base = mmio_handler->range_start; end = mmio_handler->range_end; - if ((address + size <= base) || (address >= end)) { + if (((address + size) <= base) || (address >= end)) { continue; - } else if (!((address >= base) && (address + size <= end))) { + } else if (!((address >= base) && ((address + size) <= end))) { pr_fatal("Err MMIO, address:0x%llx, size:%x", address, size); return -EIO; } else { diff --git a/hypervisor/arch/x86/trusty.c b/hypervisor/arch/x86/trusty.c index 8c0e0d70c..1e79fb850 100644 --- a/hypervisor/arch/x86/trusty.c +++ b/hypervisor/arch/x86/trusty.c @@ -118,7 +118,7 @@ static void create_secure_world_ept(struct acrn_vm *vm, uint64_t gpa_orig, */ dest_pdpte_p = pml4e_page_vaddr(sworld_pml4e); src_pdpte_p = pml4e_page_vaddr(nworld_pml4e); - for (i = 0U; i < PTRS_PER_PDPTE - 1; i++) { + for (i = 0U; i < (PTRS_PER_PDPTE - 1UL); i++) { pdpte = get_pgentry(src_pdpte_p); if ((pdpte & table_present) != 0UL) { pdpte &= ~EPT_EXE; diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index 2d8be9244..868139265 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -652,9 +652,9 @@ static int32_t write_protect_page(struct acrn_vm *vm,const struct wp_data *wp) vm->vm_id, wp->gpa, hpa); base_paddr = get_hv_image_base(); - if (((hpa <= base_paddr) && (hpa + CPU_PAGE_SIZE > base_paddr)) || + if (((hpa <= base_paddr) && ((hpa + CPU_PAGE_SIZE) > base_paddr)) || ((hpa >= base_paddr) && - (hpa < base_paddr + CONFIG_HV_RAM_SIZE))) { + (hpa < (base_paddr + CONFIG_HV_RAM_SIZE)))) { pr_err("%s: overlap the HV memory region.", __func__); return -EINVAL; } diff --git a/hypervisor/debug/profiling.c b/hypervisor/debug/profiling.c index 0cb21b674..110e892ca 100644 --- a/hypervisor/debug/profiling.c +++ b/hypervisor/debug/profiling.c @@ -278,7 +278,7 @@ static int profiling_sbuf_put_variable(struct shared_buf *sbuf, /* 2nd part */ to = (void *)sbuf + SBUF_HEAD_SIZE; - if (size - offset > 0U) { + if ((size - offset) > 0U) { (void)memcpy_s(to, size - offset, data + offset, size - offset); } @@ -372,12 +372,12 @@ static int profiling_generate_data(int32_t collector, uint32_t type) return 0; } - for (i = 0U; i < ((DATA_HEADER_SIZE - 1U) / SEP_BUF_ENTRY_SIZE + 1U); i++) { + for (i = 0U; i < (((DATA_HEADER_SIZE - 1U) / SEP_BUF_ENTRY_SIZE) + 1U); i++) { (void)sbuf_put((struct shared_buf *)sbuf, (uint8_t *)&pkt_header + i * SEP_BUF_ENTRY_SIZE); } - for (i = 0U; i < ((payload_size - 1U) / SEP_BUF_ENTRY_SIZE + 1U); i++) { + for (i = 0U; i < (((payload_size - 1U) / SEP_BUF_ENTRY_SIZE) + 1U); i++) { (void)sbuf_put((struct shared_buf *)sbuf, (uint8_t *)payload + i * SEP_BUF_ENTRY_SIZE); } diff --git a/hypervisor/lib/crypto/mbedtls/hkdf.c b/hypervisor/lib/crypto/mbedtls/hkdf.c index ada40d02f..35a61aa58 100644 --- a/hypervisor/lib/crypto/mbedtls/hkdf.c +++ b/hypervisor/lib/crypto/mbedtls/hkdf.c @@ -167,7 +167,7 @@ int mbedtls_hkdf_expand( const mbedtls_md_info_t *md, const unsigned char *prk, goto exit; } - num_to_copy = i != n ? hash_len : okm_len - where; + num_to_copy = (i != n) ? hash_len : (okm_len - where); memcpy_s( okm + where, num_to_copy, t, num_to_copy ); where += hash_len; t_len = hash_len; diff --git a/hypervisor/lib/sprintf.c b/hypervisor/lib/sprintf.c index 1298cb56e..f382db47f 100644 --- a/hypervisor/lib/sprintf.c +++ b/hypervisor/lib/sprintf.c @@ -567,7 +567,7 @@ charmem(size_t cmd, const char *s_arg, uint32_t sz, struct snprint_param *param) } /* fill mode */ else { - n = (sz < param->sz - param->wrtn) ? sz : 0U; + n = (sz < (param->sz - param->wrtn)) ? sz : 0U; param->wrtn += sz; (void)memset(p, (uint8_t)*s, n); }