KVM: PIT: fix kpit_elapsed division by zero
authorMarcelo Tosatti <mtosatti@redhat.com>
Thu, 2 Jul 2009 23:02:15 +0000 (20:02 -0300)
committerAvi Kivity <avi@redhat.com>
Wed, 5 Aug 2009 10:58:11 +0000 (13:58 +0300)
Fix division by zero triggered by latch count command on uninitialized
counter.

Cc: stable@kernel.org
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/kvm/i8254.c

index 4d6f0d293ee29bb303dbe5e4b81b4cb3c9e2b6e2..21f68e00524f51e32ad479f80446a515c1f6817a 100644 (file)
@@ -104,6 +104,9 @@ static s64 __kpit_elapsed(struct kvm *kvm)
        ktime_t remaining;
        struct kvm_kpit_state *ps = &kvm->arch.vpit->pit_state;
 
+       if (!ps->pit_timer.period)
+               return 0;
+
        /*
         * The Counter does not stop when it reaches zero. In
         * Modes 0, 1, 4, and 5 the Counter ``wraps around'' to