Skip to content

Commit 500784a

Browse files
tobluxgregkh
authored andcommitted
btrfs: scrub: replace max_t()/min_t() with clamp() in scrub_throttle_dev_io()
[ Upstream commit a7f3dfb ] Replace max_t() followed by min_t() with a single clamp(). As was pointed by David Laight in https://lore.kernel.org/linux-btrfs/20250906122458.75dfc8f0@pumpkin/ the calculation may overflow u32 when the input value is too large, so clamp_t() is not used. In practice the expected values are in range of megabytes to gigabytes (throughput limit) so the bug would not happen. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Reviewed-by: David Sterba <dsterba@suse.com> [ Use clamp() and add explanation. ] Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent cfc90c1 commit 500784a

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

fs/btrfs/scrub.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,8 +1270,7 @@ static void scrub_throttle_dev_io(struct scrub_ctx *sctx, struct btrfs_device *d
12701270
* Slice is divided into intervals when the IO is submitted, adjust by
12711271
* bwlimit and maximum of 64 intervals.
12721272
*/
1273-
div = max_t(u32, 1, (u32)(bwlimit / (16 * 1024 * 1024)));
1274-
div = min_t(u32, 64, div);
1273+
div = clamp(bwlimit / (16 * 1024 * 1024), 1, 64);
12751274

12761275
/* Start new epoch, set deadline */
12771276
now = ktime_get();

0 commit comments

Comments
 (0)