From cdad04184fbc9284deb957bdebd6406f1c7615fd Mon Sep 17 00:00:00 2001 From: Illyas Mansoor Date: Tue, 30 Aug 2011 16:40:55 +0530 Subject: [PATCH] PMU: fix divide by zero in pmu_stat_seq_printf 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 --- arch/x86/platform/mfld/pmu.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/arch/x86/platform/mfld/pmu.c b/arch/x86/platform/mfld/pmu.c index 2eed140..bdaf4e3 100755 --- a/arch/x86/platform/mfld/pmu.c +++ b/arch/x86/platform/mfld/pmu.c @@ -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); } -- 2.7.4