Skip to contentSkip to conversation

KVM: PPC: Book3S HV: radix: Fix uninitialized var build error

PATCH Applied Michael Ellerman 2 participants 2 messages Jan 1, 2019 – Jan 2, 2019

Subsystems (2)
lore
Share & tools
lore

Michael Ellerman

author reviewer
#0 lore raw

PATCH 1/1 KVM: PPC: Book3S HV: radix: Fix uninitialized var build error

Old GCCs (4.6.3 at least), aren't able to follow the logic in __kvmhv_copy_tofrom_guest_radix() and warn that old_pid is used uninitialized:

arch/powerpc/kvm/book3s_64_mmu_radix.c:75:3: error: 'old_pid' may be used uninitialized in this function

The logic is OK, we only use old_pid if quadrant = 1, and in that case it has definitely be initialised, eg:

	if (quadrant = 1) {
		old_pid = mfspr(SPRN_PID);
	...
	if (quadrant = 1 && pid != old_pid)
		mtspr(SPRN_PID, old_pid);

Annotate it to fix the error.

---
 arch/powerpc/kvm/book3s_64_mmu_radix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/book3s_64_mmu_radix.c +1 -1
index fb88167a402a..1b821c6efdef 100644
@@ -33,8 +33,8 @@ unsigned long __kvmhv_copy_tofrom_guest_radix(int lpid, int pid,
 					      gva_t eaddr, void *to, void *from,
 					      unsigned long n)
 {
+	int uninitialized_var(old_pid), old_lpid;
 	unsigned long quadrant, ret = n;
-	int old_pid, old_lpid;
 	bool is_load = !!to;
 
 	/* Can't access quadrants 1 or 2 in non-HV mode, call the HV to do it */
Signature · 1 line
2.17.2
#1 lore raw
Quoted 16 lines · Michael Ellerman

Old GCCs (4.6.3 at least), aren't able to follow the logic in __kvmhv_copy_tofrom_guest_radix() and warn that old_pid is used uninitialized:

arch/powerpc/kvm/book3s_64_mmu_radix.c:75:3: error: 'old_pid' may be used uninitialized in this function

The logic is OK, we only use old_pid if quadrant = 1, and in that case it has definitely be initialised, eg:

	if (quadrant = 1) {
		old_pid = mfspr(SPRN_PID);
	...
	if (quadrant = 1 && pid != old_pid)
		mtspr(SPRN_PID, old_pid);
Quoted 3 lines

Annotate it to fix the error.

Applied to powerpc fixes.

https://git.kernel.org/powerpc/c/f460772291f8171988b2b60141a457

cheers