KVM: x86: Use ARRAY_SIZE instead of dividing sizeof array with sizeof an element
[linux-2.6-microblaze.git] / arch / x86 / kvm / vmx.c
index c1d655c..e564fa2 100644 (file)
@@ -1112,7 +1112,7 @@ static inline bool cpu_has_broken_vmx_preemption_timer(void)
 
        /* Clear the reserved bits */
        eax &= ~(0x3U << 14 | 0xfU << 28);
-       for (i = 0; i < sizeof(vmx_preemption_cpu_tfms)/sizeof(u32); i++)
+       for (i = 0; i < ARRAY_SIZE(vmx_preemption_cpu_tfms); i++)
                if (eax == vmx_preemption_cpu_tfms[i])
                        return true;
 
@@ -10829,9 +10829,9 @@ static inline int u64_shl_div_u64(u64 a, unsigned int shift,
 static int vmx_set_hv_timer(struct kvm_vcpu *vcpu, u64 guest_deadline_tsc)
 {
        struct vcpu_vmx *vmx = to_vmx(vcpu);
-       u64 tscl = rdtsc(), delta_tsc;
-
-       delta_tsc = guest_deadline_tsc - kvm_read_l1_tsc(vcpu, tscl);
+       u64 tscl = rdtsc();
+       u64 guest_tscl = kvm_read_l1_tsc(vcpu, tscl);
+       u64 delta_tsc = max(guest_deadline_tsc, guest_tscl) - guest_tscl;
 
        /* Convert to host delta tsc if tsc scaling is enabled */
        if (vcpu->arch.tsc_scaling_ratio != kvm_default_tsc_scaling_ratio &&