aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smirnov <[email protected]>2024-03-05 16:45:09 +0300
committerJens Axboe <[email protected]>2024-03-06 08:31:54 -0700
commit93f52fbeaf4b676b21acfe42a5152620e6770d02 (patch)
treea88d2800745928881702da81773690cc54950722
parente6dfe748f09e37f77437bd337f891f5b57d5d5a2 (diff)
block: prevent division by zero in blk_rq_stat_sum()
The expression dst->nr_samples + src->nr_samples may have zero value on overflow. It is necessary to add a check to avoid division by zero. Found by Linux Verification Center (linuxtesting.org) with Svace. Signed-off-by: Roman Smirnov <[email protected]> Reviewed-by: Sergey Shtylyov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
-rw-r--r--block/blk-stat.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/block/blk-stat.c b/block/blk-stat.c
index 7ff76ae6c76a..e42c263e53fb 100644
--- a/block/blk-stat.c
+++ b/block/blk-stat.c
@@ -27,7 +27,7 @@ void blk_rq_stat_init(struct blk_rq_stat *stat)
/* src is a per-cpu stat, mean isn't initialized */
void blk_rq_stat_sum(struct blk_rq_stat *dst, struct blk_rq_stat *src)
{
- if (!src->nr_samples)
+ if (dst->nr_samples + src->nr_samples <= dst->nr_samples)
return;
dst->min = min(dst->min, src->min);