HV: fix vmptable misc violations
Fix the violations list below:
1.Function should have one return entry.
2.Do not use -- or ++ operation.
3.For loop should be simple, shall not use comma operations.
Acked-by: Eddie Dong
@@ -65,18 +65,18 @@ static struct proc_entry proc_entry_template = {
.feature_flags = MPEP_FEATURES
};
-static uint8_t mpt_compute_checksum(void *base, size_t len)
+static uint8_t mpt_compute_checksum(const void *base, size_t len)
{
- uint8_t *bytes;
- uint8_t sum;
- size_t length = len;
+ uint8_t sum = 0U;
+ size_t length;
+ const uint8_t *bytes = base;
- for (bytes = base, sum = 0U; length > 0U; length--) {
+ for (length = len; length > 0U; length--) {
sum += *bytes;
bytes++;
}
- return (256U - sum);
+ return (~sum) + 1U;
}
/**
@@ -92,6 +92,7 @@ int32_t mptable_build(struct acrn_vm *vm)
size_t mptable_length;
uint16_t i;
uint16_t vcpu_num;
+ int32_t ret = 0;
uint64_t pcpu_bitmap = 0U;
struct mptable_info *mptable;
struct acrn_vm_config *vm_config;
@@ -110,10 +111,7 @@ int32_t mptable_build(struct acrn_vm *vm)
+ MPEII_NUM_LOCAL_IRQ * sizeof(struct int_entry);
mptable_length = sizeof(struct mpfps) + mptable->mpch.base_table_length;
- if (mptable_length > MPTABLE_MAX_LENGTH) {
- return -1;
- }
-
+ if (mptable_length <= MPTABLE_MAX_LENGTH) {
for (i = 0U; i < vcpu_num; i++) {
uint16_t pcpu_id = ffs64(pcpu_bitmap);
@@ -139,6 +137,10 @@ int32_t mptable_build(struct acrn_vm *vm)
mpch = (struct mpcth *)curraddr;
mpch->checksum = mpt_compute_checksum(mpch, mpch->base_table_length);
clac();
+ ret = 0;
+ } else {
+ ret = -1;
+ }
- return 0U;
+ return ret;
}
