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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 arm/kvm-cpu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

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;
-- 
2.40.1




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux