PMU: fix divide by zero in pmu_stat_seq_printf
authorIllyas Mansoor <illyas.mansoor@intel.com>
Tue, 30 Aug 2011 11:10:55 +0000 (16:40 +0530)
committermgross <mark.gross@intel.com>
Wed, 9 Nov 2011 20:37:31 +0000 (12:37 -0800)
When echo clear > /d/mid_pmu_states is done,
and immediately "cat /d/mid_pmu_states" is
called, the variable init_2_now_time could be zero.

t = cpu_clock(raw_smp_processor_id());
t -= pmu_init_time;

init_2_now_time = (unsigned long) t;

remainder = do_div(t, init_2_now_time);

Fixed this by checking for init_2_now_time for zero.

Change-Id: I2bdd22526622327007e52cd93ebbe82fd78e72d2
Signed-off-by: Illyas Mansoor <illyas.mansoor@intel.com>
arch/x86/platform/mfld/pmu.c

index 2eed140..bdaf4e3 100755 (executable)
@@ -246,14 +246,19 @@ static void pmu_stat_seq_printf(struct seq_file *s, int type, char *typestr)
        /* for calculating percentage residency */
        time = time * 100;
        t = (u64) time;
-       remainder = do_div(t, init_2_now_time);
-       time = (unsigned long) t;
-
-       /* for getting 3 digit precision after
-        * decimal dot */
-       remainder *= 1000;
-       t = (u64) remainder;
-       remainder = do_div(t, init_2_now_time);
+       /* take care of divide by zero */
+       if (init_2_now_time) {
+               remainder = do_div(t, init_2_now_time);
+               time = (unsigned long) t;
+
+               /* for getting 3 digit precision after
+                * decimal dot */
+               remainder *= 1000;
+               t = (u64) remainder;
+               remainder = do_div(t, init_2_now_time);
+       } else
+               time = t = 0;
+
        seq_printf(s, "%5lu.%03lu\n", time, (unsigned long) t);
 }