Skip to content

Commit

Permalink
Merge tag 'block-6.6-2023-10-27' of git://git.kernel.dk/linux
Browse files Browse the repository at this point in the history
Pull block fix from Jens Axboe:
 "Just a single fix for a potential divide-by-zero, introduced in this
  cycle"

* tag 'block-6.6-2023-10-27' of git://git.kernel.dk/linux:
  blk-throttle: check for overflow in calculate_bytes_allowed
  • Loading branch information
Linus Torvalds committed Oct 28, 2023
2 parents 832328c + 2dd710d commit 2dc4e0f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions block/blk-throttle.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,12 @@ static unsigned int calculate_io_allowed(u32 iops_limit,

static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
{
/*
* Can result be wider than 64 bits?
* We check against 62, not 64, due to ilog2 truncation.
*/
if (ilog2(bps_limit) + ilog2(jiffy_elapsed) - ilog2(HZ) > 62)
return U64_MAX;
return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ);
}

Expand Down

0 comments on commit 2dc4e0f

Please sign in to comment.