backend: fix potential divide-by-zero
authorJens Axboe <axboe@fb.com>
Mon, 14 Apr 2014 15:51:10 +0000 (09:51 -0600)
committerJens Axboe <axboe@fb.com>
Mon, 14 Apr 2014 15:51:10 +0000 (09:51 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
backend.c

index b05e5437705ccf7cb4957b9c656a84cd76eaaa11..c1c8f96774850a755681dffa710d0ee1550fe16b 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -182,7 +182,11 @@ static int __check_min_rate(struct thread_data *td, struct timeval *now,
                                                                ratemin);
                                return 1;
                        } else {
-                               rate = ((bytes - td->rate_bytes[ddir]) * 1000) / spent;
+                               if (spent)
+                                       rate = ((bytes - td->rate_bytes[ddir]) * 1000) / spent;
+                               else
+                                       rate = 0;
+
                                if (rate < ratemin ||
                                    bytes < td->rate_bytes[ddir]) {
                                        log_err("%s: min rate %u not met, got"