[PATCH] LoongArch: KVM: Ensure ret is always initialized in kvm_eiointc_{read,write}()

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

 



Clang warns (or errors with CONFIG_WERROR=y):

  arch/loongarch/kvm/intc/eiointc.c:512:2: error: variable 'ret' is used uninitialized whenever switch default is taken [-Werror,-Wsometimes-uninitialized]
    512 |         default:
        |         ^~~~~~~
  arch/loongarch/kvm/intc/eiointc.c:716:2: error: variable 'ret' is used uninitialized whenever switch default is taken [-Werror,-Wsometimes-uninitialized]
    716 |         default:
        |         ^~~~~~~

Set ret to -EINVAL in the default case to resolve the warning, as len
was not a valid value for the functions to handle.

Fixes: f810ef038c66 ("LoongArch: KVM: Add EIOINTC read and write functions")
Signed-off-by: Nathan Chancellor <nathan@xxxxxxxxxx>
---
 arch/loongarch/kvm/intc/eiointc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/loongarch/kvm/intc/eiointc.c b/arch/loongarch/kvm/intc/eiointc.c
index 414e4ffd69173dc248ba0042bed3bebdc11700e3..e5d23f0da055c97c0e4ba6705f6b71d89846f42a 100644
--- a/arch/loongarch/kvm/intc/eiointc.c
+++ b/arch/loongarch/kvm/intc/eiointc.c
@@ -512,6 +512,7 @@ static int kvm_eiointc_write(struct kvm_vcpu *vcpu,
 	default:
 		WARN_ONCE(1, "%s: Abnormal address access:addr 0x%llx,size %d\n",
 						__func__, addr, len);
+		ret = -EINVAL;
 	}
 	loongarch_ext_irq_unlock(eiointc, flags);
 	return ret;
@@ -716,6 +717,7 @@ static int kvm_eiointc_read(struct kvm_vcpu *vcpu,
 	default:
 		WARN_ONCE(1, "%s: Abnormal address access:addr 0x%llx,size %d\n",
 						__func__, addr, len);
+		ret = -EINVAL;
 	}
 	loongarch_ext_irq_unlock(eiointc, flags);
 	return ret;

---
base-commit: 357da696640e1db8fc8829a4dd1bb2d0402169b5
change-id: 20240916-loongarch-kvm-eiointc-fix-sometimes-uninitialized-e17b039d2813

Best regards,
-- 
Nathan Chancellor <nathan@xxxxxxxxxx>





[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