Skip to content

Commit 4fd5102

Browse files
junjunshan1lijinxia
authored andcommitted
hv:treewide:fix multiple MISRAC violations
MISRAC has requirements about literal value requires a U suffix and signed/unsigned conversion with cast. This patch is used to solve these violations. v1->v2 *Drop the cast of sz from uint32_t to int32_t, the signed/unsigned violation of nchars will be solved by other patch together with printf/sprintf/console/vuart/uart code. *Delete the unnecessary L suffix of shifting operand. Tracked-On: #861 Signed-off-by: Junjun Shan <junjun.shan@intel.com> Reviewed by: Junjie Mao <junjie.mao@intel.com>
1 parent 00edd83 commit 4fd5102

File tree

15 files changed

+50
-50
lines changed

15 files changed

+50
-50
lines changed

hypervisor/arch/x86/guest/instr_emul.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -639,15 +639,15 @@ build_getcc(getcc64, uint64_t, x, y)
639639
static uint64_t getcc(uint8_t opsize, uint64_t x, uint64_t y)
640640
{
641641
switch (opsize) {
642-
case 1:
643-
return getcc8((uint8_t) x, (uint8_t) y);
644-
case 2:
645-
return getcc16((uint16_t) x, (uint16_t) y);
646-
case 4:
647-
return getcc32((uint32_t) x, (uint32_t) y);
648-
default: /* opsize == 8 */
649-
return getcc64(x, y);
650-
}
642+
case 1U:
643+
return getcc8((uint8_t) x, (uint8_t) y);
644+
case 2U:
645+
return getcc16((uint16_t) x, (uint16_t) y);
646+
case 4U:
647+
return getcc32((uint32_t) x, (uint32_t) y);
648+
default: /* opsize == 8 */
649+
return getcc64(x, y);
650+
}
651651
}
652652

653653
static int emulate_mov(struct vcpu *vcpu, struct instr_emul_vie *vie)
@@ -740,7 +740,7 @@ static int emulate_mov(struct vcpu *vcpu, struct instr_emul_vie *vie)
740740
* REX + C6/0 mov r/m8, imm8
741741
*/
742742
size = 1U; /* override for byte operation */
743-
error = mmio_write(vcpu, vie->immediate);
743+
error = mmio_write(vcpu, (uint64_t)vie->immediate);
744744
break;
745745
case 0xC7U:
746746
/*

hypervisor/arch/x86/mmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,15 @@ void *alloc_paging_struct(void)
265265
ptr = alloc_page();
266266

267267
ASSERT(ptr != NULL, "page alloc failed!");
268-
(void)memset(ptr, 0, CPU_PAGE_SIZE);
268+
(void)memset(ptr, 0U, CPU_PAGE_SIZE);
269269

270270
return ptr;
271271
}
272272

273273
void free_paging_struct(void *ptr)
274274
{
275275
if (ptr != NULL) {
276-
(void)memset(ptr, 0, CPU_PAGE_SIZE);
276+
(void)memset(ptr, 0U, CPU_PAGE_SIZE);
277277
free(ptr);
278278
}
279279
}

hypervisor/arch/x86/timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static uint64_t pit_calibrate_tsc(uint32_t cal_ms_arg)
261261
*/
262262
static uint64_t native_calibrate_tsc(void)
263263
{
264-
uint64_t tsc_hz = 0;
264+
uint64_t tsc_hz = 0UL;
265265

266266
if (boot_cpu_data.cpuid_level >= 0x15U) {
267267
uint32_t eax_denominator, ebx_numerator, ecx_hz, reserved;
@@ -275,7 +275,7 @@ static uint64_t native_calibrate_tsc(void)
275275
}
276276
}
277277

278-
if ((tsc_hz == 0) && (boot_cpu_data.cpuid_level >= 0x16U)) {
278+
if ((tsc_hz == 0UL) && (boot_cpu_data.cpuid_level >= 0x16U)) {
279279
uint32_t eax_base_mhz, ebx_max_mhz, ecx_bus_mhz, edx;
280280
cpuid(0x16U, &eax_base_mhz, &ebx_max_mhz, &ecx_bus_mhz, &edx);
281281
tsc_hz = (uint64_t) eax_base_mhz * 1000000U;

hypervisor/arch/x86/trusty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void create_secure_world_ept(struct vm *vm, uint64_t gpa_orig,
6565
uint64_t gpa = 0UL;
6666
uint64_t hpa = gpa2hpa(vm, gpa_orig);
6767
uint64_t table_present = EPT_RWX;
68-
uint64_t pdpte = 0, *dest_pdpte_p = NULL, *src_pdpte_p = NULL;
68+
uint64_t pdpte = 0UL, *dest_pdpte_p = NULL, *src_pdpte_p = NULL;
6969
void *sub_table_addr = NULL, *pml4_base = NULL;
7070
struct vm *vm0 = get_vm_from_vmid(0U);
7171
uint16_t i;

hypervisor/arch/x86/vmx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,14 +681,14 @@ static void init_guest_state(struct vcpu *vcpu)
681681

682682
if (vcpu_mode == CPU_MODE_REAL) {
683683
init_guest_context_real(vcpu);
684-
init_guest_vmx(vcpu, CR0_ET | CR0_NE, 0, 0);
684+
init_guest_vmx(vcpu, CR0_ET | CR0_NE, 0UL, 0UL);
685685
} else if (is_vm0(vcpu->vm) && is_vcpu_bsp(vcpu)) {
686686
init_guest_context_vm0_bsp(vcpu);
687687
init_guest_vmx(vcpu, init_ctx->cr0, init_ctx->cr3,
688688
init_ctx->cr4 & ~CR4_VMXE);
689689
} else {
690690
init_guest_context_protect(vcpu);
691-
init_guest_vmx(vcpu, CR0_ET | CR0_NE | CR0_PE, 0, 0);
691+
init_guest_vmx(vcpu, CR0_ET | CR0_NE | CR0_PE, 0UL, 0UL);
692692
}
693693
}
694694

@@ -984,7 +984,7 @@ static void init_exec_ctrl(struct vcpu *vcpu)
984984
exec_vmwrite64(VMX_EOI_EXIT2_FULL, 0UL);
985985
exec_vmwrite64(VMX_EOI_EXIT3_FULL, 0UL);
986986

987-
exec_vmwrite16(VMX_GUEST_INTR_STATUS, 0);
987+
exec_vmwrite16(VMX_GUEST_INTR_STATUS, 0U);
988988
}
989989

990990
/* Load EPTP execution control

hypervisor/boot/acpi.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
#define ACPI_SIG_MADT "APIC" /* Multiple APIC Description Table */
3737
#define ACPI_SIG_DMAR "DMAR"
3838
#define RSDP_CHECKSUM_LENGTH 20
39-
#define ACPI_NAME_SIZE 4
40-
#define ACPI_MADT_TYPE_LOCAL_APIC 0
39+
#define ACPI_NAME_SIZE 4U
40+
#define ACPI_MADT_TYPE_LOCAL_APIC 0U
4141
#define ACPI_MADT_ENABLED 1U
4242
#define ACPI_OEM_TABLE_ID_SIZE 8
4343

@@ -113,7 +113,7 @@ biosacpi_search_rsdp(char *base, int length)
113113

114114
/* compare signature, validate checksum */
115115
if (strncmp(rsdp->signature, ACPI_SIG_RSDP,
116-
strnlen_s(ACPI_SIG_RSDP, 8)) == 0) {
116+
strnlen_s(ACPI_SIG_RSDP, 8U)) == 0) {
117117
cp = (uint8_t *)rsdp;
118118
sum = 0U;
119119
for (idx = 0; idx < RSDP_CHECKSUM_LENGTH; idx++) {
@@ -179,12 +179,12 @@ static void *get_acpi_tbl(const char *sig)
179179
struct acpi_table_rsdp *rsdp;
180180
struct acpi_table_rsdt *rsdt;
181181
struct acpi_table_xsdt *xsdt;
182-
uint64_t addr = 0;
183-
int i, count;
182+
uint64_t addr = 0UL;
183+
uint32_t i, count;
184184

185185
rsdp = (struct acpi_table_rsdp *)global_rsdp;
186186

187-
if ((rsdp->revision >= 2) && (rsdp->xsdt_physical_address != 0U)) {
187+
if ((rsdp->revision >= 2U) && (rsdp->xsdt_physical_address != 0UL)) {
188188
/*
189189
* AcpiOsGetRootPointer only verifies the checksum for
190190
* the version 1.0 portion of the RSDP. Version 2.0 has
@@ -196,7 +196,7 @@ static void *get_acpi_tbl(const char *sig)
196196
sizeof(struct acpi_table_header)) /
197197
sizeof(uint64_t);
198198

199-
for (i = 0; i < count; i++) {
199+
for (i = 0U; i < count; i++) {
200200
if (probe_table(xsdt->table_offset_entry[i], sig) != 0) {
201201
addr = xsdt->table_offset_entry[i];
202202
break;
@@ -210,7 +210,7 @@ static void *get_acpi_tbl(const char *sig)
210210
sizeof(struct acpi_table_header)) /
211211
sizeof(uint32_t);
212212

213-
for (i = 0; i < count; i++) {
213+
for (i = 0U; i < count; i++) {
214214
if (probe_table(rsdt->table_offset_entry[i], sig) != 0) {
215215
addr = rsdt->table_offset_entry[i];
216216
break;
@@ -223,7 +223,7 @@ static void *get_acpi_tbl(const char *sig)
223223

224224
static uint16_t local_parse_madt(void *madt, uint8_t lapic_id_array[MAX_PCPU_NUM])
225225
{
226-
uint16_t pcpu_id = 0;
226+
uint16_t pcpu_id = 0U;
227227
struct acpi_madt_local_apic *processor;
228228
struct acpi_table_madt *madt_ptr;
229229
void *first;

hypervisor/common/hypercall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ int32_t hcall_setup_hv_npk_log(struct vm *vm, uint64_t param)
828828
{
829829
struct hv_npk_log_param npk_param;
830830

831-
memset((void *)&npk_param, 0, sizeof(npk_param));
831+
memset((void *)&npk_param, 0U, sizeof(npk_param));
832832

833833
if (copy_from_gpa(vm, &npk_param, param, sizeof(npk_param)) != 0) {
834834
pr_err("%s: Unable copy param from vm\n", __func__);

hypervisor/common/vm_load.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int load_guest(struct vm *vm, struct vcpu *vcpu)
9696
lowmem_gpa_top = *(uint64_t *)hva;
9797

9898
/* hardcode vcpu entry addr(kernel entry) & rsi (zeropage)*/
99-
for (i = 0; i < NUM_GPRS; i++) {
99+
for (i = 0U; i < NUM_GPRS; i++) {
100100
vcpu_set_gpreg(vcpu, i, 0UL);
101101
}
102102

@@ -170,7 +170,7 @@ int general_sw_loader(struct vm *vm, struct vcpu *vcpu)
170170
/* Documentation states: ebx=0, edi=0, ebp=0, esi=ptr to
171171
* zeropage
172172
*/
173-
for (i = 0; i < NUM_GPRS; i++) {
173+
for (i = 0U; i < NUM_GPRS; i++) {
174174
vcpu_set_gpreg(vcpu, i, 0UL);
175175
}
176176

hypervisor/debug/dump.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static void dump_guest_stack(struct vcpu *vcpu)
9898
{
9999
uint32_t i;
100100
uint64_t tmp[DUMP_STACK_SIZE], fault_addr;
101-
uint32_t err_code = 0;
101+
uint32_t err_code = 0U;
102102

103103
if (copy_from_gva(vcpu, tmp, vcpu_get_gpreg(vcpu, CPU_REG_RSP),
104104
DUMP_STACK_SIZE, &err_code, &fault_addr) < 0) {
@@ -112,7 +112,7 @@ static void dump_guest_stack(struct vcpu *vcpu)
112112
for (i = 0U; i < (DUMP_STACK_SIZE >> 5U); i++) {
113113
printf("guest_rsp(0x%llx): 0x%016llx 0x%016llx "
114114
"0x%016llx 0x%016llx\r\n",
115-
(vcpu_get_gpreg(vcpu, CPU_REG_RSP)+(i*32)),
115+
(vcpu_get_gpreg(vcpu, CPU_REG_RSP)+(i*32U)),
116116
tmp[i*4], tmp[(i*4)+1],
117117
tmp[(i*4)+2], tmp[(i*4)+3]);
118118
}
@@ -142,7 +142,7 @@ static void show_guest_call_trace(struct vcpu *vcpu)
142142
* try to print out call trace,here can not check if the rbp is valid
143143
* if the address is invalid, it will cause hv page fault
144144
* then halt system */
145-
while ((count < CALL_TRACE_HIERARCHY_MAX) && (bp != 0)) {
145+
while ((count < CALL_TRACE_HIERARCHY_MAX) && (bp != 0UL)) {
146146
uint64_t parent_bp = 0UL, fault_addr;
147147

148148
err_code = 0U;
@@ -215,7 +215,7 @@ static void show_host_call_trace(uint64_t rsp, uint64_t rbp_arg, uint16_t pcpu_i
215215
&& (cb_hierarchy < CALL_TRACE_HIERARCHY_MAX)) {
216216
printf("----> 0x%016llx\r\n",
217217
*(uint64_t *)(rbp + sizeof(uint64_t)));
218-
if (*(uint64_t *)(rbp + (2*sizeof(uint64_t)))
218+
if (*(uint64_t *)(rbp + (2U*sizeof(uint64_t)))
219219
== SP_BOTTOM_MAGIC) {
220220
break;
221221
}

hypervisor/debug/logmsg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static void do_copy_earlylog(struct shared_buf *dst_sbuf,
7171

7272
void init_logmsg(__unused uint32_t mem_size, uint32_t flags)
7373
{
74-
int16_t pcpu_id;
74+
uint16_t pcpu_id;
7575

7676
logmsg.flags = flags;
7777
logmsg.seq = 0;
@@ -201,7 +201,7 @@ void print_logmsg_buffer(uint16_t pcpu_id)
201201

202202
do {
203203
uint32_t idx;
204-
(void)memset(buffer, 0U, LOG_ENTRY_SIZE + 1);
204+
(void)memset(buffer, 0U, LOG_ENTRY_SIZE + 1U);
205205

206206
if (*sbuf == NULL) {
207207
return;

0 commit comments

Comments
 (0)