Skip to contentSkip to conversation

ARM(64): KVM: add signed type cast for comparation

PATCH In review Chen Gang 2 participants 4 messages Jul 22, 2013 – Jul 30, 2013

Subsystems (2)
lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 ARM(64): KVM: add signed type cast for comparation

'len' is 'unsigned long' which is never less than zero.

So need a related type cast for comparation.

The related warning (when building ARM64 with allmodconfig):

arch/arm64/kvm/../../../arch/arm/kvm/mmio.c:82:2: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]

---
 arch/arm/kvm/mmio.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/kvm/mmio.c +1 -1
index b8e06b7..626dfc8 100644
@@ -79,7 +79,7 @@ static int decode_hsr(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	}
 
 	len = kvm_vcpu_dabt_get_as(vcpu);
-	if (unlikely(len < 0))
+	if (unlikely((long)len < 0))
 		return len;
 
 	is_write = kvm_vcpu_dabt_iswrite(vcpu);
Signature · 1 line
1.7.7.6
author
#1 lore raw

Hello Maintainers:

Please help check the patch whether OK or not, when you have time.

Thanks.

Quoted 28 lines · Chen Gang

'len' is 'unsigned long' which is never less than zero.

So need a related type cast for comparation.

The related warning (when building ARM64 with allmodconfig):

arch/arm64/kvm/../../../arch/arm/kvm/mmio.c:82:2: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]

---
 arch/arm/kvm/mmio.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/kvm/mmio.c +1 -1
index b8e06b7..626dfc8 100644
@@ -79,7 +79,7 @@ static int decode_hsr(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	}
 
 	len = kvm_vcpu_dabt_get_as(vcpu);
-	if (unlikely(len < 0))
+	if (unlikely((long)len < 0))
 		return len;
 
 	is_write = kvm_vcpu_dabt_iswrite(vcpu);
Signature · 1 line
Chen Gang
#2 lore raw
In reply to Chen Gang
Quoted 8 lines · Chen Gang

'len' is 'unsigned long' which is never less than zero.

So need a related type cast for comparation.

The related warning (when building ARM64 with allmodconfig):

arch/arm64/kvm/../../../arch/arm/kvm/mmio.c:82:2: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]

Hmmm, interesting, I don't get this error with my compiler.

Quoted 21 lines
---
 arch/arm/kvm/mmio.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/kvm/mmio.c +1 -1
index b8e06b7..626dfc8 100644
@@ -79,7 +79,7 @@ static int decode_hsr(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	}
 
 	len = kvm_vcpu_dabt_get_as(vcpu);
-	if (unlikely(len < 0))
+	if (unlikely((long)len < 0))
 		return len;
 
 	is_write = kvm_vcpu_dabt_iswrite(vcpu);
Signature · 1 line
1.7.7.6

I think the proper fix is to declare len as an int instead. I'll queue that instead.

Thanks,
-Christoffer

author
#3 lore raw
Quoted 30 lines · Christoffer Dall
Quoted 8 lines · Chen Gang

'len' is 'unsigned long' which is never less than zero.

So need a related type cast for comparation.

The related warning (when building ARM64 with allmodconfig):

arch/arm64/kvm/../../../arch/arm/kvm/mmio.c:82:2: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]

Hmmm, interesting, I don't get this error with my compiler.

Quoted 18 lines
---
 arch/arm/kvm/mmio.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/kvm/mmio.c +1 -1
index b8e06b7..626dfc8 100644
@@ -79,7 +79,7 @@ static int decode_hsr(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	}
 
 	len = kvm_vcpu_dabt_get_as(vcpu);
-	if (unlikely(len < 0))
+	if (unlikely((long)len < 0))
 		return len;
 
Quoted 7 lines
Quoted 3 lines
arch/arm/kvm/mmio.c +0 -0
 	is_write = kvm_vcpu_dabt_iswrite(vcpu);
Signature · 1 line
1.7.7.6

I think the proper fix is to declare len as an int instead. I'll queue that instead.

Yeah, it is fine to me (better than my original fix).

Thanks.

Signature · 1 line
Chen Gang