hv: cpu_state_tbl: fix multiple exits
This patch fixes the MISRA-C violations in arch/x86/cpu_state_tbl.c
* make the function have only one exit point
Acked-by: Eddie Dong
@@ -106,19 +106,18 @@ static int32_t get_state_tbl_idx(const char *cpuname)
{
int32_t i;
int32_t count = ARRAY_SIZE(cpu_state_tbl);
+ int32_t ret = -1;
- if (cpuname == NULL) {
- return -1;
- }
-
+ if (cpuname != NULL) {
for (i = 0; i < count; i++) {
- if (strcmp((cpu_state_tbl[i].model_name),
- cpuname) == 0) {
- return i;
+ if (strcmp((cpu_state_tbl[i].model_name), cpuname) == 0) {
+ ret = i;
+ break;
+ }
}
}
- return -1;
+ return ret;
}
void load_cpu_state_data(void)
@@ -126,14 +125,12 @@ void load_cpu_state_data(void)
int32_t tbl_idx;
const struct cpu_state_info *state_info;
- (void)memset(&boot_cpu_data.state_info, 0U,
- sizeof(struct cpu_state_info));
+ (void)memset(&boot_cpu_data.state_info, 0U, sizeof(struct cpu_state_info));
tbl_idx = get_state_tbl_idx(boot_cpu_data.model_name);
- if (tbl_idx < 0) {
- /* The state table is not found. */
- return;
- }
+
+ if (tbl_idx >= 0) {
+ /* The state table is found. */
state_info = &(cpu_state_tbl + tbl_idx)->state_info;
@@ -156,5 +153,5 @@ void load_cpu_state_data(void)
boot_cpu_data.state_info.cx_data = state_info->cx_data;
}
-
+ }
}
