From: Jens Axboe Date: Fri, 16 Sep 2016 15:11:04 +0000 (-0600) Subject: io_u: fix overflow in 64-bit bssplit calculation X-Git-Tag: fio-2.14~5 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=3dd29f7c21538c164fcbd078c3f2e532a9193a04 io_u: fix overflow in 64-bit bssplit calculation If we use a random generator that has a 64-bit output, then we'll overflow in the calculation for what block size to select when bssplit= is used. Signed-off-by: Jens Axboe --- diff --git a/io_u.c b/io_u.c index b6d530f2..7b51dd2e 100644 --- a/io_u.c +++ b/io_u.c @@ -531,8 +531,7 @@ static unsigned int __get_next_buflen(struct thread_data *td, struct io_u *io_u, int ddir = io_u->ddir; unsigned int buflen = 0; unsigned int minbs, maxbs; - uint64_t frand_max; - unsigned long r; + uint64_t frand_max, r; assert(ddir_rw(ddir)); @@ -561,7 +560,7 @@ static unsigned int __get_next_buflen(struct thread_data *td, struct io_u *io_u, if (buflen < minbs) buflen = minbs; } else { - long perc = 0; + long long perc = 0; unsigned int i; for (i = 0; i < td->o.bssplit_nr[ddir]; i++) { @@ -569,7 +568,9 @@ static unsigned int __get_next_buflen(struct thread_data *td, struct io_u *io_u, buflen = bsp->bs; perc += bsp->perc; - if ((r * 100UL <= frand_max * perc) && + if (!perc) + break; + if ((r / perc <= frand_max / 100ULL) && io_u_fits(td, io_u, buflen)) break; }