dsched: Avoid integer overflow.
authorSascha Wildner <saw@online.de>
Tue, 20 Apr 2010 18:32:44 +0000 (21:32 +0300)
committerSascha Wildner <saw@online.de>
Tue, 20 Apr 2010 18:32:44 +0000 (21:32 +0300)
Multiplication of two 32 bit values can overflow the 32 bit result. Cast
one of the multiplicants to force 64 bit multiplication.

This fixes a lockup due to an infinite loop in the following while().

In-collaboration-with: aggelos

sys/dsched/fq/dsched_fq_core.c

index de07b33..21a6d40 100644 (file)
@@ -463,7 +463,8 @@ fq_balance_thread(struct fq_disk_ctx *diskctx)
                        tdio->interval_avg_latency = tdio->avg_latency;
                        tdio->interval_transactions = tdio->transactions;
                        if (tdio->interval_transactions > 0) {
-                               product = tdio->interval_avg_latency * tdio->interval_transactions;
+                               product = (int64_t)tdio->interval_avg_latency *
+                                   tdio->interval_transactions;
                                product >>= lost_bits;
                                while(total_budget >= INT64_MAX - product) {
                                        ++lost_bits;