diff mbox series

[kvmtool,2/3] arm/kvm-cpu: Fix new build warning

Message ID 20230606143733.994679-3-jean-philippe@linaro.org (mailing list archive)
State New, archived
Headers show
Series Build fixes | expand

Commit Message

Jean-Philippe Brucker June 6, 2023, 2:37 p.m. UTC
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>
---
 arm/kvm-cpu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/arm/kvm-cpu.c b/arm/kvm-cpu.c
index 98bc5fdf..a43eb90a 100644
--- a/arm/kvm-cpu.c
+++ b/arm/kvm-cpu.c
@@ -37,7 +37,7 @@  int kvm_cpu__register_kvm_arm_target(struct kvm_arm_target *target)
 
 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 @@  struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)
 	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;