Skip to content

Commit

Permalink
net/dim: Fix int overflow
Browse files Browse the repository at this point in the history
When calculating difference between samples, the values
are multiplied by 100. Large values may cause int overflow
when multiplied (usually on first iteration).
Fixed by forcing 100 to be of type unsigned long.

Fixes: 4c4dbb4 ("net/mlx5e: Move dynamic interrupt coalescing code to include/linux")
Signed-off-by: Tal Gilboa <talgi@mellanox.com>
Reviewed-by: Andy Gospodarek <gospo@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Tal Gilboa authored and David S. Miller committed Mar 30, 2018
1 parent 52a9692 commit f97c3dc
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/linux/net_dim.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static inline void net_dim_exit_parking(struct net_dim *dim)
}

#define IS_SIGNIFICANT_DIFF(val, ref) \
(((100 * abs((val) - (ref))) / (ref)) > 10) /* more than 10% difference */
(((100UL * abs((val) - (ref))) / (ref)) > 10) /* more than 10% difference */

static inline int net_dim_stats_compare(struct net_dim_stats *curr,
struct net_dim_stats *prev)
Expand Down

0 comments on commit f97c3dc

Please sign in to comment.