summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Blum <thorsten.blum@linux.dev>2025-09-01 17:01:44 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-11-02 22:14:40 +0900
commit3b838f39f4be8cefb02b523e74009cd4898f5bb1 (patch)
treea2f52f9ef346c9920f94063ab061bab42949026f
parentfb6ceb6cde7bc72938f36fda57c7175a3038cc49 (diff)
downloadlinux-3b838f39f4be8cefb02b523e74009cd4898f5bb1.tar.gz
linux-3b838f39f4be8cefb02b523e74009cd4898f5bb1.tar.bz2
linux-3b838f39f4be8cefb02b523e74009cd4898f5bb1.zip
btrfs: scrub: replace max_t()/min_t() with clamp() in scrub_throttle_dev_io()
[ Upstream commit a7f3dfb8293c4cee99743132d69863a92e8f4875 ] 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>
-rw-r--r--fs/btrfs/scrub.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 7632d652a125..4a5a5ee360e5 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1271,8 +1271,7 @@ static void scrub_throttle_dev_io(struct scrub_ctx *sctx, struct btrfs_device *d
* Slice is divided into intervals when the IO is submitted, adjust by
* bwlimit and maximum of 64 intervals.
*/
- div = max_t(u32, 1, (u32)(bwlimit / (16 * 1024 * 1024)));
- div = min_t(u32, 64, div);
+ div = clamp(bwlimit / (16 * 1024 * 1024), 1, 64);
/* Start new epoch, set deadline */
now = ktime_get();