Fix potential divide-by-zero in calc_rate()
authorJens Axboe <axboe@fb.com>
Mon, 27 Jul 2015 18:26:12 +0000 (12:26 -0600)
committerJens Axboe <axboe@fb.com>
Mon, 27 Jul 2015 18:26:12 +0000 (12:26 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
eta.c

diff --git a/eta.c b/eta.c
index aed61ecca935b1406985e9bdd64039d25a890664..f608c4e56aed8142ee24bb6e4cdf8ce9c6e57484 100644 (file)
--- a/eta.c
+++ b/eta.c
@@ -290,14 +290,19 @@ static void calc_rate(int unified_rw_rep, unsigned long mtime,
        int i;
 
        for (i = 0; i < DDIR_RWDIR_CNT; i++) {
-               unsigned long long diff;
+               unsigned long long diff, this_rate;
 
                diff = io_bytes[i] - prev_io_bytes[i];
+               if (mtime)
+                       this_rate = ((1000 * diff) / mtime) / 1024;
+               else
+                       this_rate = 0;
+
                if (unified_rw_rep) {
                        rate[i] = 0;
-                       rate[0] += ((1000 * diff) / mtime) / 1024;
+                       rate[0] += this_rate;
                } else
-                       rate[i] = ((1000 * diff) / mtime) / 1024;
+                       rate[i] = this_rate;
 
                prev_io_bytes[i] = io_bytes[i];
        }