mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-16 06:19:24 +00:00
hv: fix 'Switch case not terminated with break'
MISRA-C requires that every switch case shall be terminated with break to avoid the unintentional fall through. The code will become redundant if we enforce this rule. So, we will keep the current implementation for the following two cases. 1. The fall through is intentional. 2. The function is returned in the switch case. If we decide to eliminate the mutiple returns in one function later, this case would be handled properly at that time. What this patch does: - add the mssing break for the default case - add the pre condition for some functions and remove the corresponding panic which will never happen since the function caller could guarantee the pre condition based on the code implementation v1 -> v2: * remove the redundant cases above default in 'vlapic_get_lvtptr' * add the similar pre condition for 'lvt_off_to_idx' as 'vlapic_get_lvtptr' since all the function callers could guarantee it * remove the assertion in 'lvt_off_to_idx' since the pre condition could guarantee that the assertion will never happen * add the similar pre condition for 'vpic_set_irqstate' as 'vioapic_set_irqstate' since all the function callers could guarantee it * remove the assertion in 'vpic_set_irqstate' since the pre condition could guarantee that the assertion will never happen Tracked-On: #861 Signed-off-by: Shiqing Gao <shiqing.gao@intel.com> Reviewed-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
@@ -518,10 +518,20 @@ vlapic_set_intr_ready(struct acrn_vlapic *vlapic, uint32_t vector, bool level)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @pre offset value shall be one of the folllowing values:
|
||||
* APIC_OFFSET_CMCI_LVT
|
||||
* APIC_OFFSET_TIMER_LVT
|
||||
* APIC_OFFSET_THERM_LVT
|
||||
* APIC_OFFSET_PERF_LVT
|
||||
* APIC_OFFSET_LINT0_LVT
|
||||
* APIC_OFFSET_LINT1_LVT
|
||||
* APIC_OFFSET_ERROR_LVT
|
||||
*/
|
||||
static inline uint32_t
|
||||
lvt_off_to_idx(uint32_t offset)
|
||||
{
|
||||
uint32_t index = ~0U;
|
||||
uint32_t index;
|
||||
|
||||
switch (offset) {
|
||||
case APIC_OFFSET_CMCI_LVT:
|
||||
@@ -543,24 +553,29 @@ lvt_off_to_idx(uint32_t offset)
|
||||
index = APIC_LVT_LINT1;
|
||||
break;
|
||||
case APIC_OFFSET_ERROR_LVT:
|
||||
index = APIC_LVT_ERROR;
|
||||
break;
|
||||
default:
|
||||
/*
|
||||
* For the offset that is not handled (an invalid offset of
|
||||
* Local Vector Table), its index is assigned to a default
|
||||
* value, which indicates an invalid index.
|
||||
* The index will be checked later to guarantee the validity.
|
||||
* The function caller could guarantee the pre condition.
|
||||
* So, all of the possible 'offset' other than
|
||||
* APIC_OFFSET_ERROR_LVT has been handled in prior cases.
|
||||
*/
|
||||
index = APIC_LVT_ERROR;
|
||||
break;
|
||||
}
|
||||
ASSERT(index <= VLAPIC_MAXLVT_INDEX,
|
||||
"%s: invalid lvt index %u for offset %#x",
|
||||
__func__, index, offset);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @pre offset value shall be one of the folllowing values:
|
||||
* APIC_OFFSET_CMCI_LVT
|
||||
* APIC_OFFSET_TIMER_LVT
|
||||
* APIC_OFFSET_THERM_LVT
|
||||
* APIC_OFFSET_PERF_LVT
|
||||
* APIC_OFFSET_LINT0_LVT
|
||||
* APIC_OFFSET_LINT1_LVT
|
||||
* APIC_OFFSET_ERROR_LVT
|
||||
*/
|
||||
static inline uint32_t *
|
||||
vlapic_get_lvtptr(struct acrn_vlapic *vlapic, uint32_t offset)
|
||||
{
|
||||
@@ -570,16 +585,14 @@ vlapic_get_lvtptr(struct acrn_vlapic *vlapic, uint32_t offset)
|
||||
switch (offset) {
|
||||
case APIC_OFFSET_CMCI_LVT:
|
||||
return &lapic->lvt_cmci.v;
|
||||
case APIC_OFFSET_TIMER_LVT:
|
||||
case APIC_OFFSET_THERM_LVT:
|
||||
case APIC_OFFSET_PERF_LVT:
|
||||
case APIC_OFFSET_LINT0_LVT:
|
||||
case APIC_OFFSET_LINT1_LVT:
|
||||
case APIC_OFFSET_ERROR_LVT:
|
||||
default:
|
||||
/*
|
||||
* The function caller could guarantee the pre condition.
|
||||
* All the possible 'offset' other than APIC_OFFSET_CMCI_LVT
|
||||
* could be handled here.
|
||||
*/
|
||||
i = lvt_off_to_idx(offset);
|
||||
return &(lapic->lvt[i].v);
|
||||
default:
|
||||
panic("vlapic_get_lvt: invalid LVT\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -145,6 +145,7 @@ static uint32_t update_ept(struct vm *vm, uint64_t start,
|
||||
case MTRR_MEM_TYPE_UC:
|
||||
default:
|
||||
attr = EPT_UNCACHED;
|
||||
break;
|
||||
}
|
||||
|
||||
ept_mr_modify(vm, (uint64_t *)vm->arch_vm.nworld_eptp,
|
||||
|
Reference in New Issue
Block a user