summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorYamin Friedman <yaminf@mellanox.com>2019-07-23 10:22:47 +0300
committerDavid S. Miller <davem@davemloft.net>2019-07-25 11:34:39 -0700
commitf06d0ca45827a5790d7508de4759aed976933d4d (patch)
treef3129a536a3e647dc47f0acc9f9fcfd5230fbf4b /lib
parentc8ec4632c6ac9cda0e8c3d51aa41eeab66585bd5 (diff)
downloadlinux-0-day-f06d0ca45827a5790d7508de4759aed976933d4d.tar.gz
linux-0-day-f06d0ca45827a5790d7508de4759aed976933d4d.tar.xz
linux/dim: Fix overflow in dim calculation
While using net_dim, a dim_sample was used without ever initializing the comps value. Added use of DIV_ROUND_DOWN_ULL() to prevent potential overflow, it should not be a problem to save the final result in an int because after the division by epms the value should not be larger than a few thousand. [ 1040.127124] UBSAN: Undefined behaviour in lib/dim/dim.c:78:23 [ 1040.130118] signed integer overflow: [ 1040.131643] 134718714 * 100 cannot be represented in type 'int' Fixes: 398c2b05bbee ("linux/dim: Add completions count to dim_sample") Signed-off-by: Yamin Friedman <yaminf@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Acked-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/dim/dim.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/dim/dim.c b/lib/dim/dim.c
index 439d641ec7964..38045d6d05381 100644
--- a/lib/dim/dim.c
+++ b/lib/dim/dim.c
@@ -74,8 +74,8 @@ void dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
delta_us);
curr_stats->cpms = DIV_ROUND_UP(ncomps * USEC_PER_MSEC, delta_us);
if (curr_stats->epms != 0)
- curr_stats->cpe_ratio =
- (curr_stats->cpms * 100) / curr_stats->epms;
+ curr_stats->cpe_ratio = DIV_ROUND_DOWN_ULL(
+ curr_stats->cpms * 100, curr_stats->epms);
else
curr_stats->cpe_ratio = 0;