Skip to content

Commit ca83c09

Browse files
junjunshan1lijinxia
authored andcommitted
hv: treewide: fix multiple MISRAC violations
MISARC has requirements about Marco redefinition, usage of ++ or -- and assignment operator in boolean expression. This patch is used to solve these violations. The modifications are summarized as following: 1.The HC_VM_SET_MEMORY_REGION, HC_VM_GPA2HPA, HC_VM_SET_MEMORY_REGIONS are redefined twice in acrn_hv_des.h, so delete them to solve the macro redefinition violations. 2.The macro BUS_LOCK are redefined in bits.h and atomic.h, then delete the declaration in both two files, add a new declaration in cpu.h and include the header file. 3.modify the code to solve the improper usage of -- operators in string.c. 4.modify the while loop to for loop to avoid assignment operator in boolean expression in vlapic.c. v1 -> v2: *Modify the format of commit logs and signed-off name. *Modify the code format from 'd = d-1;' to 'd--;' to be better. Signed-off-by: Junjun Shan <junjun.shan@intel.com>
1 parent 0292e14 commit ca83c09

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,8 @@ vlapic_icrlo_write_handler(struct acrn_vlapic *vlapic)
11371137
break;
11381138
}
11391139

1140-
while ((vcpu_id = ffs64(dmask)) != INVALID_BIT_INDEX) {
1140+
for (vcpu_id = ffs64(dmask); vcpu_id != INVALID_BIT_INDEX;
1141+
vcpu_id = ffs64(dmask)) {
11411142
bitmap_clear_lock(vcpu_id, &dmask);
11421143
target_vcpu = vcpu_from_vid(vlapic->vm, vcpu_id);
11431144
if (target_vcpu == NULL) {

hypervisor/include/arch/x86/cpu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@
152152

153153
#ifndef ASSEMBLER
154154

155+
#define BUS_LOCK "lock ; "
156+
155157
/**
156158
*
157159
* Identifiers for architecturally defined registers.

hypervisor/include/lib/atomic.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929

3030
#ifndef ATOMIC_H
3131
#define ATOMIC_H
32-
33-
#define BUS_LOCK "lock ; "
32+
#include <cpu.h>
3433

3534
#define build_atomic_load(name, size, type, ptr) \
3635
static inline type name(const volatile type *ptr) \

hypervisor/include/lib/bits.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929

3030
#ifndef BITS_H
3131
#define BITS_H
32-
33-
#define BUS_LOCK "lock ; "
32+
#include <cpu.h>
3433
/**
3534
*
3635
* INVALID_BIT_INDEX means when input paramter is zero,

hypervisor/include/public/acrn_hv_defs.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@
5555
#define HC_VM_GPA2HPA BASE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x01UL)
5656
#define HC_VM_SET_MEMORY_REGIONS BASE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x02UL)
5757
#define HC_VM_WRITE_PROTECT_PAGE BASE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x03UL)
58-
#define HC_VM_SET_MEMORY_REGION BASE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x00UL)
59-
#define HC_VM_GPA2HPA BASE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x01UL)
60-
#define HC_VM_SET_MEMORY_REGIONS BASE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x02UL)
6158

6259
/* PCI assignment*/
6360
#define HC_ID_PCI_BASE 0x50UL

hypervisor/lib/string.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ char *strcpy_s(char *d_arg, size_t dmax, const char *s_arg)
210210
while (dest_avail > 0U) {
211211
if (overlap_guard == 0U) {
212212
pr_err("%s: overlap happened.", __func__);
213-
*(--d) = '\0';
213+
d--;
214+
*d = '\0';
214215
return NULL;
215216
}
216217

@@ -293,7 +294,8 @@ char *strncpy_s(char *d_arg, size_t dmax, const char *s_arg, size_t slen_arg)
293294
while (dest_avail > 0U) {
294295
if (overlap_guard == 0U) {
295296
pr_err("%s: overlap happened.", __func__);
296-
*(--d) = '\0';
297+
d--;
298+
*d = '\0';
297299
return NULL;
298300
}
299301

0 commit comments

Comments
 (0)