arm/kvm-cpu: Fix new build warning
GCC 13.1 complains about uninitialized value:
arm/kvm-cpu.c: In function 'kvm_cpu__arch_init':
arm/kvm-cpu.c:119:41: error: 'target' may be used uninitialized [-Werror=maybe-uninitialized]
119 | vcpu->cpu_compatible = target->compatible;
| ~~~~~~^~~~~~~~~~~~
arm/kvm-cpu.c:40:32: note: 'target' was declared here
40 | struct kvm_arm_target *target;
| ^~~~~~
This can't happen in practice (we call die() when no target is found), but
initialize the target variable earlier to make GCC happy.
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Link: https://lore.kernel.org/r/20230606143733.994679-3-jean-philippe@linaro.org
Signed-off-by: Will Deacon <will@kernel.org>
diff --git a/arm/kvm-cpu.c b/arm/kvm-cpu.c
index 98bc5fd..a43eb90 100644
--- a/arm/kvm-cpu.c
+++ b/arm/kvm-cpu.c
@@ -37,7 +37,7 @@
struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)
{
- struct kvm_arm_target *target;
+ struct kvm_arm_target *target = NULL;
struct kvm_cpu *vcpu;
int coalesced_offset, mmap_size, err = -1;
unsigned int i;
@@ -81,7 +81,6 @@
err = ioctl(kvm->vm_fd, KVM_ARM_PREFERRED_TARGET, &preferred_init);
if (!err) {
/* Match preferred target CPU type. */
- target = NULL;
for (i = 0; i < ARRAY_SIZE(kvm_arm_targets); ++i) {
if (!kvm_arm_targets[i])
continue;