Skip to content

Commit d7f895c

Browse files
trueptolemybonzini
authored andcommitted
target/i386/kvm: Return -1 when kvm_msr_energy_thread_init() fails
It is common practice to return a negative value (like -1) to indicate an error, and other functions in kvm_arch_init() follow this style. To avoid confusion (sometimes returned -1 indicates failure, and sometimes -1, in a same function), return -1 when kvm_msr_energy_thread_init() fails. Signed-off-by: Zhao Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent fb81c9c commit d7f895c

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

target/i386/kvm/kvm.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,7 +2936,6 @@ static int kvm_msr_energy_thread_init(KVMState *s, MachineState *ms)
29362936
{
29372937
MachineClass *mc = MACHINE_GET_CLASS(ms);
29382938
struct KVMMsrEnergy *r = &s->msr_energy;
2939-
int ret = 0;
29402939

29412940
/*
29422941
* Sanity check
@@ -2946,13 +2945,11 @@ static int kvm_msr_energy_thread_init(KVMState *s, MachineState *ms)
29462945
if (!is_host_cpu_intel()) {
29472946
error_report("The RAPL feature can only be enabled on hosts "
29482947
"with Intel CPU models");
2949-
ret = 1;
2950-
goto out;
2948+
return -1;
29512949
}
29522950

29532951
if (!is_rapl_enabled()) {
2954-
ret = 1;
2955-
goto out;
2952+
return -1;
29562953
}
29572954

29582955
/* Retrieve the virtual topology */
@@ -2974,16 +2971,14 @@ static int kvm_msr_energy_thread_init(KVMState *s, MachineState *ms)
29742971
r->host_topo.maxcpus = vmsr_get_maxcpus();
29752972
if (r->host_topo.maxcpus == 0) {
29762973
error_report("host max cpus = 0");
2977-
ret = 1;
2978-
goto out;
2974+
return -1;
29792975
}
29802976

29812977
/* Max number of packages on the host */
29822978
r->host_topo.maxpkgs = vmsr_get_max_physical_package(r->host_topo.maxcpus);
29832979
if (r->host_topo.maxpkgs == 0) {
29842980
error_report("host max pkgs = 0");
2985-
ret = 1;
2986-
goto out;
2981+
return -1;
29872982
}
29882983

29892984
/* Allocate memory for each package on the host */
@@ -2995,8 +2990,7 @@ static int kvm_msr_energy_thread_init(KVMState *s, MachineState *ms)
29952990
for (int i = 0; i < r->host_topo.maxpkgs; i++) {
29962991
if (r->host_topo.pkg_cpu_count[i] == 0) {
29972992
error_report("cpu per packages = 0 on package_%d", i);
2998-
ret = 1;
2999-
goto out;
2993+
return -1;
30002994
}
30012995
}
30022996

@@ -3013,8 +3007,7 @@ static int kvm_msr_energy_thread_init(KVMState *s, MachineState *ms)
30133007

30143008
if (s->msr_energy.sioc == NULL) {
30153009
error_report("vmsr socket opening failed");
3016-
ret = 1;
3017-
goto out;
3010+
return -1;
30183011
}
30193012

30203013
/* Those MSR values should not change */
@@ -3026,15 +3019,13 @@ static int kvm_msr_energy_thread_init(KVMState *s, MachineState *ms)
30263019
s->msr_energy.sioc);
30273020
if (r->msr_unit == 0 || r->msr_limit == 0 || r->msr_info == 0) {
30283021
error_report("can't read any virtual msr");
3029-
ret = 1;
3030-
goto out;
3022+
return -1;
30313023
}
30323024

30333025
qemu_thread_create(&r->msr_thr, "kvm-msr",
30343026
kvm_msr_energy_thread,
30353027
s, QEMU_THREAD_JOINABLE);
3036-
out:
3037-
return ret;
3028+
return 0;
30383029
}
30393030

30403031
int kvm_arch_get_default_type(MachineState *ms)
@@ -3342,7 +3333,9 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
33423333

33433334
if (s->msr_energy.enable == true) {
33443335
kvm_vm_enable_energy_msrs(s);
3345-
if (kvm_msr_energy_thread_init(s, ms)) {
3336+
3337+
ret = kvm_msr_energy_thread_init(s, ms);
3338+
if (ret < 0) {
33463339
error_report("kvm : error RAPL feature requirement not met");
33473340
exit(1);
33483341
}

0 commit comments

Comments
 (0)